static void console_execute_file_real(const char *filename) { IOHANDLE file; file = engine_openfile(filename, IOFLAG_READ); if(file) { //VOTEOPTION *current = voteoption_first; //while(current) //{ // current = current->next; // current->prev=0; //} //int i=0; //for(i;i<MAX_CLIENTS;i++) // if (game.players[i]->authed==0) // server_kick(i, "Server settings reload"); char *line; LINEREADER lr; dbg_msg("console", "executing '%s'", filename); linereader_init(&lr, file); while((line = linereader_get(&lr))) console_execute_line(line,-1); io_close(file); } else dbg_msg("console", "failed to open '%s'", filename); }
void engine_parse_arguments(int argc, char **argv) { /* load the configuration */ int i; /* check for datadir override */ for(i = 1; i < argc; i++) { if(argv[i][0] == '-' && argv[i][1] == 'd' && argv[i][2] == 0 && argc - i > 1) { str_copy(datadir, argv[i+1], sizeof(datadir)); i++; } } /* search for data directory */ engine_find_datadir(argv[0]); dbg_msg("engine/datadir", "paths used:"); dbg_msg("engine/datadir", "\t."); dbg_msg("engine/datadir", "\t%s", application_save_path); dbg_msg("engine/datadir", "\t%s", datadir); dbg_msg("engine/datadir", "saving files to: %s", application_save_path); /* check for scripts to execute */ for(i = 1; i < argc; i++) { if(argv[i][0] == '-' && argv[i][1] == 'f' && argv[i][2] == 0 && argc - i > 1) { console_execute_file(argv[i+1]); i++; } } /* search arguments for overrides */ { int i; for(i = 1; i < argc; i++) console_execute_line(argv[i],100,-1); } console_execute_file("autoexec.cfg"); //console_execute_line("tune shotgun_curvature",4,-1); /* open logfile if needed */ if(config.logfile[0]) dbg_logger_file(config.logfile); /* set default servers and load from disk*/ mastersrv_default(); mastersrv_load(); }
void GAMECONTROLLER::speedmotion(int min) { console_execute_line("tune ground_control_speed 35"); console_execute_line("tune air_control_speed 30"); console_execute_line("tune hook_fire_speed 160"); console_execute_line("tune hook_drag_speed 40"); console_execute_line("tune gun_speed 4000"); console_execute_line("tune shotgun_speed 4000"); console_execute_line("tune grenade_speed 2000"); console_execute_line("tune ground_jump_impulse 22"); console_execute_line("tune air_jump_impulse 20"); speed_tick = min*50*60; game.send_broadcast("EVENT: Speedmotion!", -1); game.create_sound_global(SOUND_CTF_CAPTURE); }
void CONSOLE::INSTANCE::execute_line(const char *line) { if(type == 0) console_execute_line(line); else { if(client_rcon_authed()) client_rcon(line); else client_rcon_auth("", line); } }
void PLAYER::on_disconnect() { kill_character(WEAPON_GAME); char buf[512]; str_format(buf, sizeof(buf), "%s has left the game", server_clientname(client_id)); game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); char cmd[64]; if (muted) { str_format(cmd, sizeof(cmd), "ban %d %d", client_id, muted/server_tickspeed()); console_execute_line(cmd,-1); } }
void PLAYER::on_disconnect() { // kill_character(WEAPON_GAME); //game.controller->on_player_death(&game.players[client_id], 0, -1); char buf[512]; str_format(buf, sizeof(buf), "%s has left the game", server_clientname(client_id)); game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); char cmd[64]; if (muted>0) { str_format(cmd, sizeof(cmd), "ban %d %d %s", client_id, muted/server_tickspeed(),"Trying to evade mute"); console_execute_line(cmd,3,-1); } dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id)); }
static void console_execute_file_real(const char *filename) { IOHANDLE file; file = engine_openfile(filename, IOFLAG_READ); if(file) { char *line; LINEREADER lr; dbg_msg("console", "executing '%s'", filename); linereader_init(&lr, file); while((line = linereader_get(&lr))) console_execute_line(line); io_close(file); } else dbg_msg("console", "failed to open '%s'", filename); }
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 GAMECONTROLLER::slowmotion(int min) { console_execute_line("tune ground_control_speed 5"); console_execute_line("tune air_control_speed 2"); console_execute_line("tune air_friction 0.55"); console_execute_line("tune hook_fire_speed 40"); console_execute_line("tune hook_drag_speed 7.5"); console_execute_line("tune gravity 0.6"); console_execute_line("tune gun_lifetime 6"); console_execute_line("tune gun_speed 500"); console_execute_line("tune shotgun_speed 500"); console_execute_line("tune shotgun_lifetime 2"); console_execute_line("tune grenade_speed 200"); console_execute_line("tune grenade_lifetime 10"); slow_tick = min*50*60; game.send_broadcast("EVENT: Slowmotion!", -1); game.create_sound_global(SOUND_CTF_CAPTURE); }
void GAMECONTROLLER::tick() { // do info message every 10 minutes if(server_tick()%(50*10*60) == 0) { game.send_chat_target(-1, "-------------------------"); game.send_chat_target(-1, "Buy Mod - 0.1"); game.send_chat_target(-1, "by ©Bobynator and ©KaiTee"); game.send_chat_target(-1, "/cmdlist - see all commands"); game.send_chat_target(-1, "/info - see aim of the game"); game.send_chat_target(-1, "-------------------------"); } // inactivity check if(!game.world.paused) for(int i = 0; i < MAX_CLIENTS; i++) if(game.players[i]) if(server_tick()%server_tickspeed() == 0 && game.players[i]->last_input != -1 && server_tick() - game.players[i]->last_input >= 120 * server_tickspeed()) if(server_tick() - game.players[i]->last_input >= 120 * server_tickspeed()) { game.players[i]->set_team(-1); // set him to spectator game.send_chat_target(i, "Inactivity Check: Are you still there?"); //portal ftw ;D } // event stuff // TODO: write event over stuff smarter! if(slow_tick > 0) slow_tick--; if(slow_tick == 0) { console_execute_line("tune_reset"); slow_tick = -1; game.send_broadcast("EVENT OVER!", -1); } if(speed_tick > 0) speed_tick--; if(speed_tick == 0) { console_execute_line("tune_reset"); speed_tick = -1; game.send_broadcast("EVENT OVER!", -1); } if(x2_tick > 0) x2_tick--; if(x2_tick == 0) { x2_tick = -1; game.send_broadcast("EVENT OVER!", -1); } if(one_hit_tick > 0) one_hit_tick--; if(one_hit_tick == 0) { one_hit_tick = -1; game.send_broadcast("EVENT OVER!", -1); } if(web_tick > 0) web_tick--; if(web_tick == 0) { web_tick = -1; game.send_broadcast("EVENT OVER!", -1); } if(server_tick()%(50*60*60) == 0 && !is_cup) { int Event = 1+(rand()%(5-1+1)); if(Event == 1) slowmotion(5); else if(Event == 2) x2(2); else if(Event == 3) one_hit(1); else if(Event == 4) speedmotion(3); else if(Event == 5) spider_web(4); } // do warmup if(warmup) { warmup--; if(!warmup) startround(); } // do potcount int enter_players = 0; if(is_cup) for(int i = 0; i < MAX_CLIENTS; i++) if(game.players[i]) { if(game.players[i]->enter_game == true) enter_players++; } if(potcount < 1 && is_cup && game_over_tick == -1) { if(server_tick()%(50*6) == 0 && enter_players > 1 && jackpot > 0) { char buf[512]; str_format(buf, sizeof(buf), "Jackpot: %d $", jackpot); game.send_broadcast(buf, -1, true); } if(enter_players == 1) { endround(); } } if(potcount > 0 && is_cup) { potcount--; char buf[512]; str_format(buf, sizeof(buf), "Jackpot: %d $ | Join-Time: %d", jackpot, potcount/50); for(int i = 0; i < MAX_CLIENTS; i++) { if(game.players[i]) { if(game.players[i]->broadcast_count < 1) game.send_broadcast(buf, i, true); } } } if(potcount == 0 && is_cup) { if(enter_players >= 2) { game.send_broadcast("Game Start!", -1); resetgame(); potcount--; char buf[512]; str_format(buf, sizeof(buf), "sv_scorelimit %d", enter_players*5); console_execute_line(buf); // start game round_start_tick = server_tick(); sudden_death = 0; game_over_tick = -1; game.world.paused = false; teamscore[0] = 0; teamscore[1] = 0; unbalanced_tick = -1; force_balanced = false; } else do_potcount(16); } if(game_over_tick != -1) { // game over.. wait for restart if(server_tick() > game_over_tick+server_tickspeed()*10) { cyclemap(); startround(); round_count++; } } // do team-balancing if (is_teamplay() && unbalanced_tick != -1 && server_tick() > unbalanced_tick+config.sv_teambalance_time*server_tickspeed()*60) { dbg_msg("game", "Balancing teams"); int t[2] = {0,0}; int tscore[2] = {0,0}; for(int i = 0; i < MAX_CLIENTS; i++) { if(game.players[i] && game.players[i]->team != -1) { t[game.players[i]->team]++; tscore[game.players[i]->team]+=game.players[i]->score; } } // are teams unbalanced? if(abs(t[0]-t[1]) >= 2) { int m = (t[0] > t[1]) ? 0 : 1; int num_balance = abs(t[0]-t[1]) / 2; do { PLAYER *p = 0; int pd = tscore[m]; for(int i = 0; i < MAX_CLIENTS; i++) { if(!game.players[i]) continue; // remember the player who would cause lowest score-difference if(game.players[i]->team == m && (!p || abs((tscore[m^1]+game.players[i]->score) - (tscore[m]-game.players[i]->score)) < pd)) { p = game.players[i]; pd = abs((tscore[m^1]+p->score) - (tscore[m]-p->score)); } } // move the player to other team without losing his score // TODO: change in player::set_team needed: player won't lose score on team-change int score_before = p->score; p->set_team(m^1); p->score = score_before; p->respawn(); p->force_balanced = true; } while (--num_balance); force_balanced = true; } unbalanced_tick = -1; } // update browse info int prog = -1; if(config.sv_timelimit > 0) prog = max(prog, (server_tick()-round_start_tick) * 100 / (config.sv_timelimit*server_tickspeed()*60)); if(config.sv_scorelimit) { if(is_teamplay()) { prog = max(prog, (teamscore[0]*100)/config.sv_scorelimit); prog = max(prog, (teamscore[1]*100)/config.sv_scorelimit); } else { for(int i = 0; i < MAX_CLIENTS; i++) { if(game.players[i]) prog = max(prog, (game.players[i]->score*100)/config.sv_scorelimit); } } } if(warmup) prog = -1; server_setbrowseinfo(gametype, prog); }