Jump to content
GIGN Forum

Sakiet Kaut Ko Par šo


Recommended Posts

Ir pienācis laiks, kad pats sadomāju kaut ko veidot. Jā jau sen zinu, kas ir HLDS, kas ir CS un ko ar viņu daru. Bet tā kā pilnībā nekad neesu nodevies šai nodarbei, tad prasu Jūs jaunos (maybe noy so young) progerus palīdzēt man :) Kā jau sapratīsiet, šo visu šitu es neesu rakstījis pats, bet mazliet pamainījis, so, ja zinat kaut ko labāku vai redzat kādas kļūdas, tad padalieties, ak jel =]

/**

* HLTV inviter / Kicker

* "invites" HLTV on player connect, disconnects when no players

*

* HLTV rcon connection originally written by

* redmist - http://www.amxmodx.org/forums/viewtopic.php?p=52405

*/

#include <amxmodx>

#include <sockets>

new Author[] = "someone"

new Plugin[] = "HLTV record/stoprecord"

new Version[] = "1.0.0.0"

new hltv_address = 0

new rconid[13]

new taskID=7234

new bool:hltv_delayed=false

public plugin_init() {

register_plugin(Plugin, Version, Author)

register_cvar("hltv_ip", "127.0.0.1") // Tava HLTV servera ip adrese

register_cvar("hltv_port", "27020") // Tava HLTV servera ports

register_cvar("hltv_rcon", "tava_hltv_rcon_parole") // HLTV server rcon

register_cvar("demo_name", "demos/name") // Kur gribi rakstit sheit: mapee demos ar nosaukumu name

register_cvar("hltv_recdelay", "60.0") // Pec cik ilga laika beigt rakstit demo, kad pedejais players iziet

set_task(60.0,"hltv_connect", taskID)

hltv_delayed = true

}

public plugin_end() {

socket_close(hltv_address)

}

public hltv_connect() {

new error=0

// Atrodam HLTV rcon paroli.

new hltv_cvar_rcon[20]

get_cvar_string("hltv_rcon", hltv_cvar_rcon,20)

if(!hltv_cvar_rcon[0]) {

log_amx("There is no HLTV rcon set!")

return PLUGIN_HANDLED

}

new hltv_cvar_ip[15]

new hltv_cvar_port=27020

// hltv ip/port/password

get_cvar_string("hltv_ip", hltv_cvar_ip,15)

hltv_cvar_port = get_cvar_num("hltv_port")

// Piekonekteejas HLTV

hltv_address = socket_open(hltv_cvar_ip, hltv_cvar_port, SOCKET_UDP, error)

if (error != 0) {

log_amx("HLTV Proxy Connection Failed - error %i", error)

return PLUGIN_HANDLED

}

hltv_challenge()

return PLUGIN_CONTINUE

}

public hltv_challenge() {

// Megjinam pievienoties HLTV

new iNum=5, i

for(i = 0; i <= iNum; i++) {

new rcv[256], snd[256]

setc(snd, 4, 0xff)

copy(snd[4], 255, "challenge rcon")

setc(snd[18], 1, '^n')

socket_send(hltv_address, snd, 255)

socket_recv(hltv_address, rcv, 255)

copy(rconid, 12, rcv[19])

replace(rconid, 255, "^n", "")

if(rconid[0]) continue

}

if(!rconid[0]) {

log_amx("Could not get rcon challenge")

return PLUGIN_HANDLED

}

return PLUGIN_CONTINUE

}

public client_connect(id) {

// If HLTV connection not available, try connecting first

if(hltv_address <= 0) {

log_amx("HLTV connection not available, trying to reconnect...")

hltv_connect()

if(hltv_address <= 0) {

// Still no connection. Give up.

log_amx("HLTV connection still not available, giving up :(. Maybe next time...")

return PLUGIN_HANDLED

}

}

// If HLTV disconnection is delayed, remove it

if(hltv_delayed) {

hltv_delayed = false

remove_task(taskID)

// We could think that HLTV _is_ on server here,

// but to be certain, don't to assumpions

}

new iPlayers[32], iNum, i;

get_players(iPlayers, iNum);

// Go thru player to see if HLTV is one of them

for(i = 0; i <= iNum; i++) {

// If HLTV connected, don't do shit.

if(is_user_hltv(iPlayers) && is_user_connected (iPlayers)) return PLUGIN_CONTINUE

}

// Call HLTV to start recording.

hltv_record()

return PLUGIN_CONTINUE

}

public client_disconnect(id) {

if(hltv_address <= 0) {

log_amx("HLTV connection not available, trying to reconnect...")

hltv_connect()

if(hltv_address <= 0) {

// Still no connection. Give up.

log_amx("...HLTV connection still not available, giving up :(. Maybe next time...")

return PLUGIN_HANDLED

}

}

new hltv

new iPlayers[32], iNum, i;

get_players(iPlayers, iNum);

for(i = 0; i <= iNum; i++) {

// If HLTV connected, mark it

if(iPlayers == 0) {

// This is the server, you stupid!

continue

} else if(is_user_hltv(iPlayers)) {

hltv = iPlayers

} else if(is_user_bot(iPlayers)) {

continue

} else if(iPlayers == id) {

// Skip disconnecting player

continue

} else {

// KILL TEH HUMANS...

// No, just be happy that were not alone, and don't commit suicide.

return PLUGIN_CONTINUE

}

}

// If HLTV was not detected, end this shit

if(!hltv) {

return PLUGIN_CONTINUE

}

// We delay HLTV disconnection, if eg, player is retrying

new Float:time=60.0

time = get_cvar_float("hltv_recdelay")

set_task(time,"hltv_stoprecording",taskID)

hltv_delayed = true

return PLUGIN_CONTINUE

}

public hltv_stoprecording() {

// First, remove delayed flag

if(hltv_delayed) {

hltv_delayed = false

}

new cmd[64]

// Stop recording

log_amx("Calling HLTV to stop recording")

format(cmd,63,"stoprecording")

hltv_rcon_cmd(cmd)

return PLUGIN_CONTINUE

}

public hltv_record() {

new cmd[64]

new demo_name[20]

get_cvar_string("demo_name",demo_name,20)

format(cmd, 63,"record %s",demo_name)

log_amx("Calling HLTV to start recording.")

hltv_rcon_cmd(cmd)

return PLUGIN_CONTINUE

}

public hltv_rcon_cmd(cmd[]) {

// If HLTV connection not available, try connecting first

if(hltv_address <= 0) {

log_amx("HLTV connection not available, trying to reconnect...")

hltv_connect()

if(hltv_address <= 0) {

// Still no connection. Give up.

log_amx("...HLTV connection still not available, giving up :(. Maybe next time...")

return PLUGIN_HANDLED

}

}

// Just to be sure, get challenge

hltv_challenge()

new snd[256]

new hltv_cvar_rcon[20]

get_cvar_string("hltv_rcon",hltv_cvar_rcon,20)

// send rcon command

setc(snd,255,0x00)

setc(snd,4,0xff)

format(snd[4],255,"rcon %s ^"%s^" %s^n",rconid,hltv_cvar_rcon,cmd)

socket_send(hltv_address,snd,255)

return PLUGIN_CONTINUE

}

Ideju gan jau ka sapratīsiet. Vienkārši vajag pluginu, kas saka HLTV, lai sāk rakstīt, kad pievienojas pirmais geimers vai arī pabeidz rakstīt demo, kad pēdējais players iziet.

hltvrecord.txt

Edited by Gariks
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...