void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_EMOTICON, flags); msg_pack_int(cid); msg_pack_int(emoticon); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_CHAT, flags); msg_pack_int(team); msg_pack_int(cid); msg_pack_string(message, -1); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_VOTE_STATUS, flags); msg_pack_int(yes); msg_pack_int(no); msg_pack_int(pass); msg_pack_int(total); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_KILLMSG, flags); msg_pack_int(killer); msg_pack_int(victim); msg_pack_int(weapon); msg_pack_int(mode_special); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_CHANGEINFO, flags); msg_pack_string(name, -1); msg_pack_string(skin, -1); msg_pack_int(use_custom_color); msg_pack_int(color_body); msg_pack_int(color_feet); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_SAY, flags); msg_pack_int(team); msg_pack_string(message, -1); msg_pack_end(); }
static void server_send_map(int cid) { msg_pack_start_system(NETMSG_MAP_CHANGE, MSGFLAG_VITAL|MSGFLAG_FLUSH); msg_pack_string(config.sv_map, 0); msg_pack_int(current_map_crc); msg_pack_end(); server_send_msg(cid); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_VOTE_SET, flags); msg_pack_int(timeout); msg_pack_string(description, -1); msg_pack_string(command, -1); msg_pack_end(); }
void send_tuning_params(int cid) { msg_pack_start(NETMSGTYPE_SV_TUNEPARAMS, MSGFLAG_VITAL); int *params = (int *)&tuning; for(unsigned i = 0; i < sizeof(tuning)/sizeof(int); i++) msg_pack_int(params[i]); msg_pack_end(); server_send_msg(cid); }
void msg_pack_start(int msg, int flags) { packer_reset(&msg_packer); pack_info.msg = msg<<1; pack_info.flags = flags; packer_failed = 0; msg_pack_int(pack_info.msg); }
void CHARACTER::fire_weapon() { if(reload_timer != 0 || freezetime > 0) return; do_weaponswitch(); vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y)); bool fullauto = false; if(active_weapon == WEAPON_GRENADE || active_weapon == WEAPON_SHOTGUN || active_weapon == WEAPON_RIFLE) fullauto = true; if(active_weapon == WEAPON_GUN && player->ak==1) fullauto = true; if(active_weapon == WEAPON_NINJA && col_get_ninjafly((int)pos.x, (int)pos.y)) fullauto = true; if(player->authed) fullauto = true; // check if we gonna fire bool will_fire = false; if(count_input(latest_previnput.fire, latest_input.fire).presses) will_fire = true; if(fullauto && (latest_input.fire&1) && weapons[active_weapon].ammo) will_fire = true; if(!will_fire) return; // check for ammo if(!weapons[active_weapon].ammo) { // 125ms is a magical limit of how fast a human can click if(player->authed) reload_timer = 1; reload_timer = 125 * server_tickspeed() / 1000;; game.create_sound(pos, SOUND_WEAPON_NOAMMO); return; } vec2 projectile_startpos = pos+direction*phys_size*0.75f; switch(active_weapon) { case WEAPON_HAMMER: { if(player->authed) { game.create_explosion(pos, 0, 0, true); game.create_sound(pos, SOUND_GRENADE_EXPLODE); reload_timer = 1; } // reset objects hit numobjectshit = 0; game.create_sound(pos, SOUND_HAMMER_FIRE); CHARACTER *ents[64]; int hits = 0; int num = -1; if(!game.controller->is_race() || (game.controller->is_race() && (config.sv_teamdamage || config.sv_enemy_damage))) num = game.world.find_entities(pos+direction*phys_size*0.75f, phys_size*0.5f, (ENTITY**)ents, 64, NETOBJTYPE_CHARACTER); for (int i = 0; i < num; i++) { CHARACTER *target = ents[i]; if (target == this) continue; // hit a player, give him damage and stuffs... vec2 fdir = normalize(ents[i]->pos - pos); // set his velocity to fast upward (for now) game.create_hammerhit(pos); if(config.sv_water_insta && ents[i]->team != team) { ents[i]->take_damage(vec2(0,-1.0f), 0, player->client_id, active_weapon); if(config.sv_water_strip && ents[i]->team != team && ents[i]->weapons[WEAPON_RIFLE].got) { ents[i]->weapons[WEAPON_RIFLE].got = false; //ents[i]->freezetime = config.sv_water_freezetime*2; if(ents[i]->active_weapon == WEAPON_RIFLE) ents[i]->active_weapon=WEAPON_HAMMER; } ents[i]->freezetime = config.sv_water_freezetime; game.send_emoticon(ents[i]->player->client_id, 12); } else ents[i]->take_damage(vec2(0,-1.0f), data->weapons.hammer.base->damage, player->client_id, active_weapon); vec2 dir; if (length(target->pos - pos) > 0.0f) dir = normalize(target->pos - pos); else dir = vec2(0,-1); target->core.vel += normalize(dir + vec2(0,-1.1f)) * 10.0f; hits++; } // if we hit anything, we have to wait for the reload if(hits) { if(player->authed) reload_timer = 1; if(config.sv_water_insta) { reload_timer = config.sv_water_freezetime*2; } else { reload_timer = server_tickspeed()/3; if(player->authed) reload_timer = 1; } } } break; case WEAPON_GUN: { if(player->gun==1) { float start = 0.0f; if (2%2==0) start = (-2/2 + 0.5)*135*0.001; else start = (-(2-1)/2)*135*0.001; for (float i = 0; i < 2; i+=1.0f) { float a = start+get_angle(direction)+i*135*0.001; float speed = 1.0f; float v = 1-fabs((i*135*0.001f+start)/start); if (0) speed = mix((float)750*0.001f, 1.0f, v); PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, player->client_id, projectile_startpos, vec2(cos(a), sin(a))*speed+vec2(0, -0*0.001f), (int)(server_tickspeed()*tuning.gun_lifetime), 5, 0, 0, SOUND_GRENADE_EXPLODE, WEAPON_GUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); } } if(player->authed) { float start = 0.0f; if (3%2==0) start = (-3/2 + 0.5)*70*0.001; else start = (-(3-1)/2)*70*0.001; for (float i = 0; i < 3; i+=1.0f) { float a = start+get_angle(direction)+i*70*0.001; float speed = 1.0f; float v = 1-fabs((i*70*0.001f+start)/start); if (0) speed = mix((float)750*0.001f, 1.0f, v); PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, player->client_id, projectile_startpos, vec2(cos(a), sin(a))*speed+vec2(0, -0*0.001f), (int)(server_tickspeed()*tuning.gun_lifetime), 5, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); reload_timer = 5; } } PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, player->client_id, projectile_startpos, direction, (int)(server_tickspeed()*tuning.gun_lifetime), 1, 0, 0, -1, WEAPON_GUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(5); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); game.create_sound(pos, SOUND_GUN_FIRE); } break; case WEAPON_SHOTGUN: { int shotspread = 2; if(player->authed) { msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(shotspread*2+1); for(int i = -shotspread; i <= shotspread; i++) { float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; float a = get_angle(direction); a += spreading[i+2]; float v = 1-(abs(i)/(float)shotspread); float speed = mix((float)tuning.shotgun_speeddiff, 1.0f, v); PROJECTILE *proj = new PROJECTILE(WEAPON_SHOTGUN, player->client_id, projectile_startpos, vec2(cosf(a), sinf(a))*speed, (int)(server_tickspeed()*tuning.shotgun_lifetime), 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_SHOTGUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); reload_timer = config.sv_reload_shotgun_admin; } } if(player->shotgun==1) { msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(shotspread*2+1); for(int i = -shotspread; i <= shotspread; i++) { float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; float a = get_angle(direction); a += spreading[i+2]; float v = 1-(abs(i)/(float)shotspread); float speed = mix((float)tuning.shotgun_speeddiff, 1.0f, v); PROJECTILE *proj = new PROJECTILE(WEAPON_SHOTGUN, player->client_id, projectile_startpos, vec2(cosf(a), sinf(a))*speed, (int)(server_tickspeed()*tuning.shotgun_lifetime), 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_SHOTGUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); } } msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(shotspread*2+1); for(int i = -shotspread; i <= shotspread; i++) { float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; float a = get_angle(direction); a += spreading[i+2]; float v = 1-(abs(i)/(float)shotspread); float speed = mix((float)tuning.shotgun_speeddiff, 1.0f, v); PROJECTILE *proj = new PROJECTILE(WEAPON_SHOTGUN, player->client_id, projectile_startpos, vec2(cosf(a), sinf(a))*speed, (int)(server_tickspeed()*tuning.shotgun_lifetime), 1, 0, 0, -1, WEAPON_SHOTGUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); } msg_pack_end(); server_send_msg(player->client_id); game.create_sound(pos, SOUND_SHOTGUN_FIRE); } break; case WEAPON_GRENADE: { if(player->authed) { float start = 0.0f; if (5%2==0) start = (-5/2 + 0.5)*75*0.001; else start = (-(5-1)/2)*75*0.001; for (float i = 0; i < 5; i+=1.0f) { PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, player->client_id, projectile_startpos, direction+vec2(start + i*75*0.001, -100*0.001f), (int)(server_tickspeed()*tuning.grenade_lifetime), 5, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); reload_timer = config.sv_reload_grenade_admin; } game.create_sound(pos, SOUND_GRENADE_FIRE); } if(player->grenade==1) { float start = 0.0f; if (2%2==0) start = (-2/2 + 0.5)*130*0.001; else start = (-(2-1)/2)*130*0.001; for (float i = 0; i < 2; i+=1.0f) { PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, player->client_id, projectile_startpos, direction+vec2(start + i*130*0.001, -100*0.001f), (int)(server_tickspeed()*tuning.grenade_lifetime), 5, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); } game.create_sound(pos, SOUND_GRENADE_FIRE); } PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, player->client_id, projectile_startpos, direction, (int)(server_tickspeed()*tuning.grenade_lifetime), 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); game.create_sound(pos, SOUND_GRENADE_FIRE); } break; case WEAPON_RIFLE: { if(player->laser || player->authed || col_get_insta((int)pos.x, (int)pos.y)) { new LASER(pos, direction, tuning.laser_reach, player->client_id, is_water); game.create_sound(pos, SOUND_RIFLE_FIRE); if(player->authed) reload_timer = config.sv_reload_laser_admin; } else game.send_chat_target(player->client_id, "Please buy Laser in the Shop!"); } break; case WEAPON_NINJA: { attack_tick = server_tick(); ninja.activationdir = direction; ninja.currentmovetime = data->weapons.ninja.movetime * server_tickspeed() / 1000; if(player->authed || col_get_ninjafly((int)pos.x, (int)pos.y)) { ninja.currentmovetime = data->weapons.ninja.movetime * server_tickspeed() / 2875; reload_timer = 1; game.create_explosion(pos, 0, 0, true); game.create_sound(pos, SOUND_GRENADE_EXPLODE); } game.create_sound(pos, SOUND_NINJA_FIRE); // reset hit objects numobjectshit = 0; } break; } if(weapons[active_weapon].ammo > 0 && (!game.controller->is_race() || !config.sv_infinite_ammo)) // -1 == unlimited weapons[active_weapon].ammo--; attack_tick = server_tick(); if(!reload_timer) reload_timer = data->weapons.id[active_weapon].firedelay * server_tickspeed() / 1000; }
static void server_do_snap() { int i; { static PERFORMACE_INFO scope = {"presnap", 0}; perf_start(&scope); mods_presnap(); perf_end(); } /* create snapshot for demo recording */ if(demorec_isrecording()) { char data[MAX_SNAPSHOT_SIZE]; int snapshot_size; /* build snap and possibly add some messages */ snapbuild_init(&builder); mods_snap(-1); snapshot_size = snapbuild_finish(&builder, data); /* write snapshot */ demorec_record_snapshot(server_tick(), data, snapshot_size); } /* create snapshots for all clients */ for(i = 0; i < MAX_CLIENTS; i++) { /* client must be ingame to recive snapshots */ if(clients[i].state != SRVCLIENT_STATE_INGAME) continue; /* this client is trying to recover, don't spam snapshots */ if(clients[i].snap_rate == SRVCLIENT_SNAPRATE_RECOVER && (server_tick()%50) != 0) continue; /* this client is trying to recover, don't spam snapshots */ if(clients[i].snap_rate == SRVCLIENT_SNAPRATE_INIT && (server_tick()%10) != 0) continue; { char data[MAX_SNAPSHOT_SIZE]; char deltadata[MAX_SNAPSHOT_SIZE]; char compdata[MAX_SNAPSHOT_SIZE]; int snapshot_size; int crc; static SNAPSHOT emptysnap; SNAPSHOT *deltashot = &emptysnap; int deltashot_size; int delta_tick = -1; int deltasize; static PERFORMACE_INFO scope = {"build", 0}; perf_start(&scope); snapbuild_init(&builder); { static PERFORMACE_INFO scope = {"modsnap", 0}; perf_start(&scope); mods_snap(i); perf_end(); } /* finish snapshot */ snapshot_size = snapbuild_finish(&builder, data); crc = snapshot_crc((SNAPSHOT*)data); /* remove old snapshos */ /* keep 3 seconds worth of snapshots */ snapstorage_purge_until(&clients[i].snapshots, current_tick-SERVER_TICK_SPEED*3); /* save it the snapshot */ snapstorage_add(&clients[i].snapshots, current_tick, time_get(), snapshot_size, data, 0); /* find snapshot that we can preform delta against */ emptysnap.data_size = 0; emptysnap.num_items = 0; { deltashot_size = snapstorage_get(&clients[i].snapshots, clients[i].last_acked_snapshot, 0, &deltashot, 0); if(deltashot_size >= 0) delta_tick = clients[i].last_acked_snapshot; else { /* no acked package found, force client to recover rate */ if(clients[i].snap_rate == SRVCLIENT_SNAPRATE_FULL) clients[i].snap_rate = SRVCLIENT_SNAPRATE_RECOVER; } } /* create delta */ { static PERFORMACE_INFO scope = {"delta", 0}; perf_start(&scope); deltasize = snapshot_create_delta(deltashot, (SNAPSHOT*)data, deltadata); perf_end(); } if(deltasize) { /* compress it */ int snapshot_size; const int max_size = MAX_SNAPSHOT_PACKSIZE; int numpackets; int n, left; { static PERFORMACE_INFO scope = {"compress", 0}; /*char buffer[512];*/ perf_start(&scope); snapshot_size = intpack_compress(deltadata, deltasize, compdata); /*str_hex(buffer, sizeof(buffer), compdata, snapshot_size); dbg_msg("", "deltasize=%d -> %d : %s", deltasize, snapshot_size, buffer);*/ perf_end(); } numpackets = (snapshot_size+max_size-1)/max_size; for(n = 0, left = snapshot_size; left; n++) { int chunk = left < max_size ? left : max_size; left -= chunk; if(numpackets == 1) msg_pack_start_system(NETMSG_SNAPSINGLE, MSGFLAG_FLUSH); else msg_pack_start_system(NETMSG_SNAP, MSGFLAG_FLUSH); msg_pack_int(current_tick); msg_pack_int(current_tick-delta_tick); /* compressed with */ if(numpackets != 1) { msg_pack_int(numpackets); msg_pack_int(n); } msg_pack_int(crc); msg_pack_int(chunk); msg_pack_raw(&compdata[n*max_size], chunk); msg_pack_end(); server_send_msg(i); } } else { msg_pack_start_system(NETMSG_SNAPEMPTY, MSGFLAG_FLUSH); msg_pack_int(current_tick); msg_pack_int(current_tick-delta_tick); /* compressed with */ msg_pack_end(); server_send_msg(i); } perf_end(); } } mods_postsnap(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_VOTE, flags); msg_pack_int(vote); msg_pack_end(); }
static void server_process_client_packet(NETCHUNK *packet) { int cid = packet->client_id; NETADDR addr; int sys; int msg = msg_unpack_start(packet->data, packet->data_size, &sys); if(clients[cid].state == SRVCLIENT_STATE_AUTH) { if(sys && msg == NETMSG_INFO) { char version[64]; const char *password; str_copy(version, msg_unpack_string(), 64); if(strcmp(version, mods_net_version()) != 0) { /* OH F**K! wrong version, drop him */ char reason[256]; str_format(reason, sizeof(reason), "wrong version. server is running '%s' and client '%s'.", mods_net_version(), version); netserver_drop(net, cid, reason); return; } str_copy(clients[cid].name, msg_unpack_string(), MAX_NAME_LENGTH); str_copy(clients[cid].clan, msg_unpack_string(), MAX_CLANNAME_LENGTH); password = msg_unpack_string(); if(config.password[0] != 0 && strcmp(config.password, password) != 0) { /* wrong password */ netserver_drop(net, cid, "wrong password"); return; } clients[cid].state = SRVCLIENT_STATE_CONNECTING; server_send_map(cid); } } else { if(sys) { /* system message */ if(msg == NETMSG_REQUEST_MAP_DATA) { int chunk = msg_unpack_int(); int chunk_size = 1024-128; int offset = chunk * chunk_size; int last = 0; /* drop faulty map data requests */ if(chunk < 0 || offset > current_map_size) return; if(offset+chunk_size >= current_map_size) { chunk_size = current_map_size-offset; if(chunk_size < 0) chunk_size = 0; last = 1; } msg_pack_start_system(NETMSG_MAP_DATA, MSGFLAG_VITAL|MSGFLAG_FLUSH); msg_pack_int(last); msg_pack_int(current_map_size); msg_pack_int(chunk_size); msg_pack_raw(¤t_map_data[offset], chunk_size); msg_pack_end(); server_send_msg(cid); if(config.debug) dbg_msg("server", "sending chunk %d with size %d", chunk, chunk_size); } else if(msg == NETMSG_READY) { if(clients[cid].state == SRVCLIENT_STATE_CONNECTING) { netserver_client_addr(net, cid, &addr); dbg_msg("server", "player is ready. cid=%x ip=%d.%d.%d.%d", cid, addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3] ); clients[cid].state = SRVCLIENT_STATE_READY; mods_connected(cid); } } else if(msg == NETMSG_ENTERGAME) { if(clients[cid].state == SRVCLIENT_STATE_READY) { netserver_client_addr(net, cid, &addr); dbg_msg("server", "player has entered the game. cid=%x ip=%d.%d.%d.%d", cid, addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3] ); clients[cid].state = SRVCLIENT_STATE_INGAME; mods_client_enter(cid); } } else if(msg == NETMSG_INPUT) { int tick, size, i; CLIENT_INPUT *input; int64 tagtime; clients[cid].last_acked_snapshot = msg_unpack_int(); tick = msg_unpack_int(); size = msg_unpack_int(); /* check for errors */ if(msg_unpack_error() || size/4 > MAX_INPUT_SIZE) return; if(clients[cid].last_acked_snapshot > 0) clients[cid].snap_rate = SRVCLIENT_SNAPRATE_FULL; if(snapstorage_get(&clients[cid].snapshots, clients[cid].last_acked_snapshot, &tagtime, 0, 0) >= 0) clients[cid].latency = (int)(((time_get()-tagtime)*1000)/time_freq()); /* add message to report the input timing */ /* skip packets that are old */ if(tick > clients[cid].last_input_tick) { int time_left = ((server_tick_start_time(tick)-time_get())*1000) / time_freq(); msg_pack_start_system(NETMSG_INPUTTIMING, 0); msg_pack_int(tick); msg_pack_int(time_left); msg_pack_end(); server_send_msg(cid); } clients[cid].last_input_tick = tick; input = &clients[cid].inputs[clients[cid].current_input]; if(tick <= server_tick()) tick = server_tick()+1; input->game_tick = tick; for(i = 0; i < size/4; i++) input->data[i] = msg_unpack_int(); mem_copy(clients[cid].latestinput.data, input->data, MAX_INPUT_SIZE*sizeof(int)); clients[cid].current_input++; clients[cid].current_input %= 200; /* call the mod with the fresh input data */ if(clients[cid].state == SRVCLIENT_STATE_INGAME) mods_client_direct_input(cid, clients[cid].latestinput.data); } else if(msg == NETMSG_RCON_CMD) { const char *cmd = msg_unpack_string(); if(msg_unpack_error() == 0 && clients[cid].authed) { dbg_msg("server", "cid=%d rcon='%s'", cid, cmd); console_execute_line(cmd); } } else if(msg == NETMSG_RCON_AUTH) { const char *pw; msg_unpack_string(); /* login name, not used */ pw = msg_unpack_string(); if(msg_unpack_error() == 0) { if(config.sv_rcon_password[0] == 0) { server_send_rcon_line(cid, "No rcon password set on server. Set sv_rcon_password to enable the remote console."); } else if(strcmp(pw, config.sv_rcon_password) == 0) { msg_pack_start_system(NETMSG_RCON_AUTH_STATUS, MSGFLAG_VITAL); msg_pack_int(1); msg_pack_end(); server_send_msg(cid); clients[cid].authed = 1; server_send_rcon_line(cid, "Authentication successful. Remote console access granted."); dbg_msg("server", "cid=%d authed", cid); } else { server_send_rcon_line(cid, "Wrong password."); } } } else if(msg == NETMSG_PING) { msg_pack_start_system(NETMSG_PING_REPLY, 0); msg_pack_end(); server_send_msg(cid); } else { char hex[] = "0123456789ABCDEF"; char buf[512]; int b; for(b = 0; b < packet->data_size && b < 32; b++) { buf[b*3] = hex[((const unsigned char *)packet->data)[b]>>4]; buf[b*3+1] = hex[((const unsigned char *)packet->data)[b]&0xf]; buf[b*3+2] = ' '; buf[b*3+3] = 0; } dbg_msg("server", "strange message cid=%d msg=%d data_size=%d", cid, msg, packet->data_size); dbg_msg("server", "%s", buf); } } else { /* game message */ if(clients[cid].state >= SRVCLIENT_STATE_READY) mods_message(msg, cid); } }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_SETTEAM, flags); msg_pack_int(team); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_SOUNDGLOBAL, flags); msg_pack_int(soundid); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_WEAPONPICKUP, flags); msg_pack_int(weapon); msg_pack_end(); }