/* ==================== NET_Init ==================== */ void NET_Init() { #ifdef _WIN32 int r; r = WSAStartup( MAKEWORD( 1, 1 ), &winsockdata ); if ( r ) { Com_Printf( "WARNING: Winsock initialization failed, returned %d\n", r ); return; } winsockInitialized = true; Com_Printf( "Winsock Initialized\n" ); #endif #ifdef HAVE_GEOIP geoip_data_4 = NET_GeoIP_LoadData( GEOIP_COUNTRY_EDITION ); geoip_data_6 = NET_GeoIP_LoadData( GEOIP_COUNTRY_EDITION_V6 ); Com_Printf( "Loaded GeoIP data: ^%dIPv4 ^%dIPv6\n", geoip_data_4 ? 2 : 1, geoip_data_6 ? 2 : 1 ); #endif NET_Config( true ); Cmd_AddCommand( "net_restart", NET_Restart_f ); }
void CL_Connect_f(void) { char *server; if (Cmd_Argc() != 2) { Com_Printf("usage: connect <server>\n"); return; } if (Com_ServerState()) { /* if running a local server, kill it and reissue note: this is connect with the save game system */ SV_Shutdown("Server quit\n", false); } else { CL_Disconnect(); } server = Cmd_Argv(1); NET_Config(true); /* allow remote */ CL_Disconnect(); cls.state = ca_connecting; Q_strlcpy(cls.servername, server, sizeof(cls.servername)); cls.connect_time = -99999; /* HACK: CL_CheckForResend() will fire immediately */ }
/* ==================== NET_Init ==================== */ void NET_Init( void ) { int r; #ifdef _XBOX // Run NetStartup with security bypassed // this allows us to communicate with PCs while developing XNetStartupParams xnsp; ZeroMemory( &xnsp, sizeof(xnsp) ); xnsp.cfgSizeOfStruct = sizeof(xnsp); #ifdef _DEBUG xnsp.cfgFlags |= XNET_STARTUP_BYPASS_SECURITY; #else xnsp.cfgFlags |= XNET_STARTUP_BYPASS_SECURITY; // xnsp.cfgFlags = 0; #endif INT err = XNetStartup( &xnsp ); #endif r = WSAStartup( MAKEWORD( 1, 1 ), &winsockdata ); if( r ) { Com_Printf( "WARNING: Winsock initialization failed, returned %d\n", r ); return; } winsockInitialized = qtrue; Com_Printf( "Winsock Initialized\n" ); // this is really just to get the cvars registered NET_GetCvars(); //FIXME testing! NET_Config( qtrue ); }
int Sys_InitGame() { //Four args, three unused, and one I don't care to use. //char * gamedir[0x100]; //gmodinfo might need zeroing out on server restarts and whatnot, but for the //first server, there ought to be no troubles. //Tracing sucks. SeedRandomNumberGenerator(); Sys_InitMemory(); if(Host_Init(&host_parms) == 0) { //failed. return(0); } Sys_Init(); //be after host_init, as cvars need memory. //COM_GetGameDirSize(gamedir, sizeof(gamedir)); //Sys_InitAuthentication Host_InitializeGameDLL(); Banlist_Init(); NET_Config(1); return(1); }
//#include <sys/mman.h> void CL_Connect_f( void ) { string server; if( Cmd_Argc() != 2 ) { Msg( "Usage: connect <server>\n" ); return; } // default value 40000 ignored as we don't want to grow userinfo string if( ( cl_maxpacket->integer < 40000 ) && ( cl_maxpacket->integer > 99 ) ) { cl_maxpacket->flags |= CVAR_USERINFO; userinfo->modified = true; } Q_strncpy( server, Cmd_Argv( 1 ), MAX_STRING ); if( Host_ServerState()) { // if running a local server, kill it and reissue Q_strncpy( host.finalmsg, "Server quit", MAX_STRING ); SV_Shutdown( false ); } NET_Config( true ); // allow remote Msg( "server %s\n", server ); CL_Disconnect(); cls.state = ca_connecting; Q_strncpy( cls.servername, server, sizeof( cls.servername )); cls.connect_time = MAX_HEARTBEAT; // CL_CheckForResend() will fire immediately }
/* ================ CL_Connect_f ================ */ void CL_Connect_f (void) { char *server; if (Cmd_Argc() != 2) { Com_Printf ("usage: connect <server>\n"); return; } if (Com_ServerState ()) { // if running a local server, kill it and reissue SV_Shutdown (va("Server quit\n", msg), false); } else { CL_Disconnect (); } server = Cmd_Argv (1); NET_Config (true); // allow remote CL_Disconnect (); cls.state = ca_connecting; strncpy (cls.servername, server, sizeof(cls.servername)-1); cls.connect_time = -99999; // CL_CheckForResend() will fire immediately }
/* =============== SV_Startup Called when a host starts a map when it wasn't running one before. Successive map or map_restart commands will NOT cause this to be called, unless the game is exited to the menu system first. =============== */ void SV_Startup() { if ( svs.initialized ) { Com_Error( ERR_FATAL, "SV_Startup: svs.initialized" ); } SV_BoundMaxClients( 1 ); // RF, avoid trying to allocate large chunk on a fragmented zone svs.clients = ( client_t * ) calloc( sizeof( client_t ) * sv_maxclients->integer, 1 ); if ( !svs.clients ) { Com_Error( ERR_FATAL, "SV_Startup: unable to allocate svs.clients" ); } svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * 64; svs.initialized = true; Cvar_Set( "sv_running", "1" ); #ifndef BUILD_SERVER NET_Config( true ); #endif // Join the IPv6 multicast group now that a map is running, so clients can scan for us on the local network. NET_JoinMulticast6(); }
/* =============== SV_KillServer_f Kick everyone off, possibly in preparation for a new game =============== */ static void SV_KillServer_f (void) { if (!svs.initialized) return; SV_Shutdown ("Server was killed.\n", false); NET_Config ( NET_NONE ); // close network sockets }
/* =============== SV_KillServer_f Kick everyone off, possibly in preparation for a new game =============== */ void SV_KillServer_f( void ) { if( !svs.initialized ) return; Q_strncpy( host.finalmsg, "Server was killed", MAX_STRING ); SV_Shutdown( false ); NET_Config ( false ); // close network sockets }
static void M_PingServers (void) { int i; netadr_t adr = {0}; char *adrstring; if(!m_num_addresses) return; NET_Config (NET_CLIENT); // allow remote adr.type = NA_BROADCAST; adr.port = BigShort(PORT_SERVER); CL_SendUIStatusRequests(&adr); // send a packet to each address book entry for (i=0; i<m_num_addresses; i++) { adrstring = local_server_addresses[i]; Com_Printf ("pinging %s...\n", adrstring); if (!NET_StringToAdr (adrstring, &adr)) { Com_Printf ("Bad address: %s\n", adrstring); continue; } if (!adr.port) adr.port = BigShort(PORT_SERVER); CL_SendUIStatusRequests(&adr); } }
/* ==================== NET_Init ==================== */ void NET_Init (void) { // WORD wVersionRequested; int r; // wVersionRequested = MAKEWORD(1, 1); r = WSAStartup (MAKEWORD(1, 1), &winsockdata); if (r) Com_Error (ERR_FATAL,"Winsock initialization failed."); NET_Common_Init (); net_rcvbuf = Cvar_Get ("net_rcvbuf", "0", 0); net_sndbuf = Cvar_Get ("net_sndbuf", "0", 0); //r1: needed for pyroadmin hooks #ifndef NO_SERVER if (dedicated->intvalue) NET_Config (NET_SERVER); #endif Com_Printf("Winsock Initialized\n", LOG_NET); //noudp = Cvar_Get ("noudp", "0", CVAR_NOSET); //noipx = Cvar_Get ("noipx", "0", CVAR_NOSET); //net_shownet = Cvar_Get ("net_shownet", "0", 0); }
void CLQ2_PingServers_f() { NET_Config( true ); // allow remote // send a broadcast packet common->Printf( "pinging broadcast...\n" ); Cvar* noudp = Cvar_Get( "noudp", "0", CVAR_INIT ); if ( !noudp->value ) { netadr_t adr; adr.type = NA_BROADCAST; adr.port = BigShort( Q2PORT_SERVER ); NET_OutOfBandPrint( NS_CLIENT, adr, "info %i", Q2PROTOCOL_VERSION ); } // send a packet to each address book entry for ( int i = 0; i < 16; i++ ) { char name[ 32 ]; String::Sprintf( name, sizeof ( name ), "adr%i", i ); const char* adrstring = Cvar_VariableString( name ); if ( !adrstring || !adrstring[ 0 ] ) { continue; } common->Printf( "pinging %s...\n", adrstring ); netadr_t adr; if ( !SOCK_StringToAdr( adrstring, &adr, Q2PORT_SERVER ) ) { common->Printf( "Bad address: %s\n", adrstring ); continue; } NET_OutOfBandPrint( NS_CLIENT, adr, "info %i", Q2PROTOCOL_VERSION ); } }
/* * Send the rest of the command line over as * an unconnected command. */ void CL_Rcon_f(void) { char message[1024]; int i; netadr_t to; if (!rcon_client_password->string) { Com_Printf("You must set 'rcon_password' before\n" "issuing an rcon command.\n"); return; } memset(&to, 0, sizeof(to)); message[0] = (char)255; message[1] = (char)255; message[2] = (char)255; message[3] = (char)255; message[4] = 0; NET_Config(true); /* allow remote */ strcat(message, "rcon "); strcat(message, rcon_client_password->string); strcat(message, " "); for (i = 1; i < Cmd_Argc(); i++) { strcat(message, Cmd_Argv(i)); strcat(message, " "); } if (cls.state >= ca_connected) { to = cls.netchan.remote_address; } else { if (!strlen(rcon_address->string)) { Com_Printf("You must either be connected,\n" "or set the 'rcon_address' cvar\n" "to issue rcon commands\n"); return; } NET_StringToAdr(rcon_address->string, &to); if (to.port == 0) { to.port = BigShort(PORT_SERVER); } } NET_SendPacket(NS_CLIENT, strlen(message) + 1, message, to); }
void NET_Shutdown(void) { NET_Config(false); /* close sockets */ WSACleanup(); }
//#include <sys/mman.h> void CL_Connect_f( void ) { char server[ sizeof( cls.servername ) ]; if( Cmd_Argc() != 2 ) { Msg( "Usage: connect <server>\n" ); return; } Q_strncpy( server, Cmd_Argv( 1 ), sizeof( cls.servername )); if( Host_ServerState()) { // if running a local server, kill it and reissue Q_strncpy( host.finalmsg, "Server quit", MAX_STRING ); SV_Shutdown( false ); } NET_Config( true ); // allow remote Msg( "server %s\n", server ); CL_Disconnect(); cls.state = ca_connecting; Q_strncpy( cls.servername, server, sizeof( cls.servername )); cls.connect_time = MAX_HEARTBEAT; // CL_CheckForResend() will fire immediately }
/* ================== SV_Map_f Goes directly to a given map without any savegame archiving. For development work ================== */ void SV_Map_f( void ) { char *spawn_entity; string mapname; int flags; if( Cmd_Argc() != 2 ) { Msg( "Usage: map <mapname>\n" ); return; } // hold mapname to other place Q_strncpy( mapname, Cmd_Argv( 1 ), sizeof( mapname )); // determine spawn entity classname if( sv_maxclients->integer == 1 ) spawn_entity = GI->sp_entity; else spawn_entity = GI->mp_entity; flags = SV_MapIsValid( mapname, spawn_entity, NULL ); if( flags & MAP_INVALID_VERSION ) { Msg( "SV_NewMap: map %s is invalid or not supported\n", mapname ); return; } if(!( flags & MAP_IS_EXIST )) { Msg( "SV_NewMap: map %s doesn't exist\n", mapname ); return; } if(!( flags & MAP_HAS_SPAWNPOINT )) { Msg( "SV_NewMap: map %s doesn't have a valid spawnpoint\n", mapname ); return; } // init network stuff NET_Config(( sv_maxclients->integer > 1 )); // changing singleplayer to multiplayer or back. refresh the player count if(( sv_maxclients->modified ) || ( deathmatch->modified ) || ( coop->modified ) || ( teamplay->modified )) Host_ShutdownServer(); SCR_BeginLoadingPlaque( false ); sv.changelevel = false; sv.background = false; sv.loadgame = false; // set right state SV_ClearSaveDir (); // delete all temporary *.hl files SV_DeactivateServer(); SV_SpawnServer( mapname, NULL ); SV_LevelInit( mapname, NULL, NULL, false ); SV_ActivateServer (); }
/* ==================== NET_Shutdown ==================== */ void NET_Shutdown( void ) { if ( !winsockInitialized ) { return; } NET_Config( qfalse ); WSACleanup(); winsockInitialized = qfalse; }
void Sys_ShutdownGame() { //Sys_ShutdownAuthentication(); Host_Shutdown(); NET_Config(0); //Sys_ShutdownLauncherInterface(); Sys_ShutdownMemory(); //Sys_Shutdown(); }
/* ==================== NET_Shutdown ==================== */ void NET_Shutdown (void) { NET_Config(NET_NONE); // close sockets #ifdef _WIN32 WSACleanup(); #endif Cmd_RemoveCommand( "net_restart" ); }
/* * Kick everyone off, possibly in preparation for a new game */ void SV_KillServer_f(void) { if (!svs.initialized) { return; } SV_Shutdown("Server was killed.\n", false); NET_Config(false); /* close network sockets */ }
/* ================= Master_Add ================= */ void Master_Add( void ) { netadr_t adr; NET_Config( true ); // allow remote if( !NET_StringToAdr( MASTERSERVER_ADR, &adr )) MsgDev( D_INFO, "Can't resolve adr: %s\n", MASTERSERVER_ADR ); NET_SendPacket( NS_SERVER, 2, "\x4D\xFF", adr ); }
/* <d4b88> ../engine/net_ws.c:2449 */ void NET_Shutdown(void) { NET_ThreadLock(); NET_ClearLaggedList(g_pLagData); NET_ClearLaggedList(&g_pLagData[1]); NET_ThreadUnlock(); NET_Config(FALSE); NET_FlushQueues(); }
/* ==================== NET_Shutdown ==================== */ void NET_Shutdown( void ) { if ( !networkingEnabled ) { return; } NET_Config( qfalse ); #ifdef _WIN32 WSACleanup(); winsockInitialized = qfalse; #endif }
/* ================== SV_MapBackground_f Set background map (enable physics in menu) ================== */ void SV_MapBackground_f( void ) { string mapname; int flags; if( Cmd_Argc() != 2 ) { Msg( "Usage: map_background <mapname>\n" ); return; } if( sv.state == ss_active && !sv.background ) { Msg( "SV_NewMap: can't set background map while game is active\n" ); return; } // hold mapname to other place Q_strncpy( mapname, Cmd_Argv( 1 ), sizeof( mapname )); flags = SV_MapIsValid( mapname, GI->sp_entity, NULL ); if(!( flags & MAP_IS_EXIST )) { Msg( "SV_NewMap: map %s doesn't exist\n", mapname ); return; } // background maps allow without spawnpoints (just throw warning) if(!( flags & MAP_HAS_SPAWNPOINT )) MsgDev( D_WARN, "SV_NewMap: map %s doesn't have a valid spawnpoint\n", mapname ); Q_strncpy( host.finalmsg, "", MAX_STRING ); SV_Shutdown( true ); NET_Config ( false ); // close network sockets sv.background = true; sv.loadgame = false; // set right state // reset all multiplayer cvars Cvar_FullSet( "coop", "0", CVAR_LATCH ); Cvar_FullSet( "teamplay", "0", CVAR_LATCH ); Cvar_FullSet( "deathmatch", "0", CVAR_LATCH ); Cvar_FullSet( "maxplayers", "1", CVAR_LATCH ); #ifndef _DEDICATED SCR_BeginLoadingPlaque( true ); #endif SV_SpawnServer( mapname, NULL ); SV_LevelInit( mapname, NULL, NULL, false ); SV_ActivateServer (); }
/* ================= CL_LocalServers_f ================= */ void CL_LocalServers_f( void ) { netadr_t adr; MsgDev( D_INFO, "Scanning for servers on the local network area...\n" ); NET_Config( true ); // allow remote // send a broadcast packet adr.type = NA_BROADCAST; adr.port = BF_BigShort( PORT_SERVER ); Netchan_OutOfBandPrint( NS_CLIENT, adr, "info %i", PROTOCOL_VERSION ); }
void Host_GetBatchModList_f() { //Odd... master_server_t * ptr; NET_Config(1); if(gfNoMasterServer != 0 || masterlist == NULL) { return; } for(ptr = masterlist; ptr != NULL; ptr = ptr->next) { Con_Printf("Requesting batch mod status from %s", NET_AdrToString(ptr->address)); NET_SendPacket(NS_CLIENT, sizeof("x\r\nstart-of-list\r\n"), "x\r\nstart-of-list\r\n", ptr->address); } }
void M_ServerlistUpdate_f (void) { NET_Config(true); // Open up ports #if 1 // todo - cvar? M_ServerlistUpdateUDP(0); #else if (!refreshing) { refreshing = true; pthread_create(&updatethread, NULL, M_ServerlistUpdate_multithreaded, NULL); } #endif }
/* ================ SV_Shutdown Called when each game quits, before Sys_Quit or Sys_Error ================ */ void SV_Shutdown( const char *finalmsg ) { if ( !com_sv_running || !com_sv_running->integer ) { return; } PrintBanner(_( "Server Shutdown" )) NET_LeaveMulticast6(); if ( svs.clients && !com_errorEntered ) { SV_FinalCommand( va( "print %s", Cmd_QuoteString( finalmsg ) ), qtrue ); } SV_RemoveOperatorCommands(); SV_MasterShutdown(); SV_ShutdownGameProgs(); // free current level SV_ClearServer(); // free server static data if ( svs.clients ) { int index; for ( index = 0; index < sv_maxclients->integer; index++ ) { SV_FreeClient( &svs.clients[ index ] ); } //Z_Free( svs.clients ); free( svs.clients ); // RF, avoid trying to allocate large chunk on a fragmented zone } memset( &svs, 0, sizeof( svs ) ); svs.serverLoad = -1; Cvar_Set( "sv_running", "0" ); #ifndef DEDICATED NET_Config( qtrue ); #endif Com_Printf( "---------------------------\n" ); // disconnect any local clients CL_Disconnect( qfalse ); }
/* ================ SV_Shutdown Called when each game quits, before Sys_Quit or Sys_Error ================ */ void SV_Shutdown( const char *finalmsg ) { if ( !com_sv_running || !com_sv_running->integer ) { return; } PrintBanner( "Server Shutdown" ) NET_LeaveMulticast6(); if ( svs.clients ) { SV_FinalCommand( va( "print %s", Cmd_QuoteString( finalmsg ) ), true ); } SV_RemoveOperatorCommands(); SV_MasterShutdown(); SV_ShutdownGameProgs(); // free current level SV_ClearServer(); // free server static data if ( svs.clients ) { int index; for ( index = 0; index < sv_maxclients->integer; index++ ) { SV_FreeClient( &svs.clients[ index ] ); } free( svs.clients ); } memset( &svs, 0, sizeof( svs ) ); svs.serverLoad = -1; Cvar_Set( "sv_running", "0" ); #ifndef BUILD_SERVER NET_Config( true ); #endif Com_Printf( "---------------------------\n" ); // disconnect any local clients CL_Disconnect( false ); }
void CL_Passive_f (void) { if (cls.state != ca_disconnected) { Com_Printf ("Passive mode can only be modified when you are disconnected.\n", LOG_CLIENT); } else { cls.passivemode = !cls.passivemode; if (cls.passivemode) { NET_Config (NET_CLIENT); Com_Printf ("Listening for passive connections on port %d\n", LOG_CLIENT, Cvar_IntValue ("ip_clientport")); } else { Com_Printf ("No longer listening for passive connections.\n", LOG_CLIENT); } } }