//***************************************************************************** // void SERVER_MASTER_Tick( void ) { UCVarValue Val; while (( g_lStoredQueryIPHead != g_lStoredQueryIPTail ) && ( gametic >= g_StoredQueryIPs[g_lStoredQueryIPHead].lNextAllowedGametic )) { g_lStoredQueryIPHead++; g_lStoredQueryIPHead = g_lStoredQueryIPHead % MAX_STORED_QUERY_IPS; } // Send an update to the master server every 30 seconds. if ( gametic % ( TICRATE * 30 )) return; // User doesn't wish to update the master server. if ( sv_updatemaster == false ) return; NETWORK_ClearBuffer( &g_MasterServerBuffer ); Val = sv_masterip.GetGenericRep( CVAR_String ); NETWORK_StringToAddress( Val.String, &g_AddressMasterServer ); I_SetPort( g_AddressMasterServer, g_lMasterPort ); // Write to our packet a challenge to the master server. Val = sv_masteroverrideip.GetGenericRep( CVAR_String ); if ( Val.String[0] == '\0' ) NETWORK_WriteLong( &g_MasterServerBuffer, SERVER_MASTER_CHALLENGE ); else { netadr_t OverrideIP; NETWORK_WriteLong( &g_MasterServerBuffer, SERVER_MASTER_CHALLENGE_OVERRIDE ); NETWORK_StringToAddress( Val.String, &OverrideIP ); NETWORK_WriteByte( &g_MasterServerBuffer, OverrideIP.ip[0] ); NETWORK_WriteByte( &g_MasterServerBuffer, OverrideIP.ip[1] ); NETWORK_WriteByte( &g_MasterServerBuffer, OverrideIP.ip[2] ); NETWORK_WriteByte( &g_MasterServerBuffer, OverrideIP.ip[3] ); NETWORK_WriteShort( &g_MasterServerBuffer, NETWORK_GetLocalPort( )); } // Send the master server our packet. // NETWORK_LaunchPacket( &g_MasterServerBuffer, g_AddressMasterServer, true ); NETWORK_LaunchPacket( &g_MasterServerBuffer, g_AddressMasterServer ); }
void ZANDRONUM_Construct( void ) { // Setup our message buffer. NETWORK_InitBuffer( &g_MessageBuffer, 8192, BUFFERTYPE_WRITE ); NETWORK_ClearBuffer( &g_MessageBuffer ); NETWORK_StringToAddress( "master.zandronum.com", &g_AddressMasterServer ); g_AddressMasterServer.usPort = htons( DEFAULT_MASTER_PORT ); // Call ZANDRONUM_Destruct when the program terminates. atexit( ZANDRONUM_Destruct ); }
static void main_ConnectToFavorite( int iIndex ) { // Update gui. main_EnableConnectionButtons( FALSE ); SetDlgItemText( g_hDlg, IDC_SERVERIP, g_Favorites[iIndex].szAddress ); SetDlgItemText( g_hDlg, IDC_PASSWORD, g_Favorites[iIndex].szPassword ); // Connect. NETWORK_StringToAddress( g_Favorites[iIndex].szAddress, &g_ServerAddress ); strncpy( g_szPassword, g_Favorites[iIndex].szPassword, 127 ); main_AttemptConnection( ); }
void main_SetupProtocols ( ) { //===================== // Setup the protocols. //===================== // Skulltag (www.skulltag.com) g_PortInfo[PORT_SKULLTAG].pvQueryMasterServer = SKULLTAG_QueryMasterServer; g_PortInfo[PORT_SKULLTAG].pvParseMasterServerResponse = SKULLTAG_ParseMasterServerResponse; g_PortInfo[PORT_SKULLTAG].pvQueryServer = SKULLTAG_QueryServer; g_PortInfo[PORT_SKULLTAG].pvParseServerResponse = SKULLTAG_ParseServerResponse; g_PortInfo[PORT_SKULLTAG].bHuffman = true; g_PortInfo[PORT_SKULLTAG].bEnabled = true; strcpy( g_PortInfo[PORT_SKULLTAG].szName, "Skulltag" ); g_PortInfo[PORT_SKULLTAG].iOverviewNowLabelID = IDC_OVERVIEW_STPLAYERS_NOW; g_PortInfo[PORT_SKULLTAG].iOverviewTodayLabelID = IDC_OVERVIEW_STPLAYERS_TOD; g_PortInfo[PORT_SKULLTAG].iOnTopNowIconID = IDC_ONTOPNOW_ST; g_PortInfo[PORT_SKULLTAG].iOnTopTodayIconID = IDC_ONTOPTODAY_ST; NETWORK_StringToAddress( "skulltag.servegame.com", &g_PortInfo[PORT_SKULLTAG].MasterServerInfo.Address ); g_PortInfo[PORT_SKULLTAG].MasterServerInfo.Address.usPort = htons( 15300 ); SKULLTAG_Construct( ); // ZDaemon (www.zdaemon.org) g_PortInfo[PORT_ZDAEMON].pvQueryMasterServer = ZDAEMON_QueryMasterServer; g_PortInfo[PORT_ZDAEMON].pvParseMasterServerResponse = ZDAEMON_ParseMasterServerResponse; g_PortInfo[PORT_ZDAEMON].pvQueryServer = ZDAEMON_QueryServer; g_PortInfo[PORT_ZDAEMON].pvParseServerResponse = ZDAEMON_ParseServerResponse; g_PortInfo[PORT_ZDAEMON].bHuffman = false; g_PortInfo[PORT_ZDAEMON].bEnabled = false; strcpy( g_PortInfo[PORT_ZDAEMON].szName, "ZDaemon" ); g_PortInfo[PORT_ZDAEMON].iOverviewNowLabelID = IDC_OVERVIEW_ZDPLAYERS_NOW; g_PortInfo[PORT_ZDAEMON].iOverviewTodayLabelID = IDC_OVERVIEW_ZDPLAYERS_TOD; g_PortInfo[PORT_ZDAEMON].iOnTopNowIconID = IDC_ONTOPNOW_ZD; g_PortInfo[PORT_ZDAEMON].iOnTopTodayIconID = IDC_ONTOPTODAY_ZD; NETWORK_StringToAddress( "zdaemon.ath.cx", &g_PortInfo[PORT_ZDAEMON].MasterServerInfo.Address ); g_PortInfo[PORT_ZDAEMON].MasterServerInfo.Address.usPort = htons( 15300 ); ZDAEMON_Construct( ); }
//***************************************************************************** // NETADDRESS_s NETWORK_AUTH_GetServerAddress( void ) { NETADDRESS_s authServerAddress; // [BB] Initialize the port with 0. NETWORK_StringToAddress will change // it in case authhostname contains a port. authServerAddress.usPort = 0; UCVarValue Val = authhostname.GetGenericRep( CVAR_String ); if ( NETWORK_StringToAddress( Val.String, &authServerAddress ) == false ) Printf ( "Warning: Can't find authhostname %s!\n", Val.String ); // [BB] If authhostname doesn't include the port, use the default port. if ( authServerAddress.usPort == 0 ) NETWORK_SetAddressPort( authServerAddress, DEFAULT_AUTH_SERVER_PORT ); return ( authServerAddress ); }
//***************************************************************************** // void IPList::addEntry( const char *pszIPAddress, const char *pszPlayerName, const char *pszComment, std::string &Message, time_t tExpiration ) { NETADDRESS_s BanAddress; char szStringBan[4][4]; if ( NETWORK_StringToIP( pszIPAddress, szStringBan[0], szStringBan[1], szStringBan[2], szStringBan[3] )) addEntry( szStringBan[0], szStringBan[1], szStringBan[2], szStringBan[3], pszPlayerName, pszComment, Message, tExpiration ); else if ( NETWORK_StringToAddress( pszIPAddress, &BanAddress )) { itoa( BanAddress.abIP[0], szStringBan[0], 10 ); itoa( BanAddress.abIP[1], szStringBan[1], 10 ); itoa( BanAddress.abIP[2], szStringBan[2], 10 ); itoa( BanAddress.abIP[3], szStringBan[3], 10 ); addEntry( szStringBan[0], szStringBan[1], szStringBan[2], szStringBan[3], pszPlayerName, pszComment, Message, tExpiration ); } else { Message = "Invalid IP address string: "; Message += pszIPAddress; Message += "\n"; } }
//***************************************************************************** // bool IPFileParser::parseNextLine( FILE *pFile, IPADDRESSBAN_s &IP, ULONG &BanIdx ) { NETADDRESS_s IPAddress; char szIP[257]; int lPosition; lPosition = 0; szIP[0] = 0; char curChar = fgetc( pFile ); // Skip whitespace. if ( curChar == ' ' ) { curChar = skipWhitespace( pFile ); if ( feof( pFile )) { return ( false ); } } while ( 1 ) { if ( curChar == '\r' || curChar == '\n' || curChar == ':' || curChar == '<' || curChar == '/' || curChar == -1 ) { if ( lPosition > 0 ) { if ( NETWORK_StringToIP( szIP, IP.szIP[0], IP.szIP[1], IP.szIP[2], IP.szIP[3] )) { if ( BanIdx == _listLength ) { sprintf( _errorMessage, "parseNextLine: WARNING! Maximum number of IPs (%d) exceeded!\n", _listLength ); return ( false ); } // [RC] Read the expiration date. if ( curChar == '<' ) { IP.tExpirationDate = readExpirationDate( pFile ); curChar = fgetc( pFile ); continue; } else { BanIdx++; // [BB] If there is a reason given why the IP is on the list, read it now. if ( curChar == ':' ) readReason( pFile, IP.szComment, 128 ); else IP.szComment[0] = 0; return ( true ); } } else if ( NETWORK_StringToAddress( szIP, &IPAddress )) { if ( BanIdx == _listLength ) { sprintf( _errorMessage, "parseNextLine: WARNING! Maximum number of IPs (%d) exceeded!\n", _listLength ); return ( false ); } _itoa( IPAddress.abIP[0], IP.szIP[0], 10 ); _itoa( IPAddress.abIP[1], IP.szIP[1], 10 ); _itoa( IPAddress.abIP[2], IP.szIP[2], 10 ); _itoa( IPAddress.abIP[3], IP.szIP[3], 10 ); IP.tExpirationDate = 0; BanIdx++; // [BB] If there is a reason given why the IP is on the list, read it now. if ( curChar == ':' ) readReason( pFile, IP.szComment, 128 ); return ( true ); } else { IP.szIP[0][0] = 0; IP.szIP[1][0] = 0; IP.szIP[2][0] = 0; IP.szIP[3][0] = 0; } } if ( feof( pFile )) { return ( false ); } // If we've hit a comment, skip until the end of the line (or the end of the file) and get out. else if ( curChar == ':' || curChar == '/' ) { skipComment( pFile ); return ( true ); } else return ( true ); } szIP[lPosition++] = curChar; szIP[lPosition] = 0; if ( lPosition == 256 ) { return ( false ); } curChar = fgetc( pFile ); } }
//***************************************************************************** // NETADDRESS_s NETWORK_GetLocalAddress( void ) { char szBuffer[512]; struct sockaddr_in SocketAddress; NETADDRESS_s Address; int iNameLength; #ifndef __WINE__ gethostname( szBuffer, 512 ); #endif szBuffer[512-1] = 0; // Convert the host name to our local bool stringToAddress = NETWORK_StringToAddress( szBuffer, &Address ); iNameLength = sizeof( SocketAddress ); #ifndef WIN32 if ( getsockname ( g_NetworkSocket, (struct sockaddr *)&SocketAddress, (socklen_t *)&iNameLength) == -1 ) #else if ( getsockname ( g_NetworkSocket, (struct sockaddr *)&SocketAddress, &iNameLength ) == -1 ) #endif { Printf( "NETWORK_GetLocalAddress: Error getting socket name: %s", strerror( errno )); } #ifdef unix // [BB] The "gethostname -> gethostbyname" trick didn't reveal the local IP. // Now we need to resort to something more complicated. if ( stringToAddress == false ); { #ifndef __FreeBSD__ unsigned char *u; int size = 1; struct ifreq *ifr; struct ifconf ifc; struct sockaddr_in sa; ifc.ifc_len = IFRSIZE; ifc.ifc_req = NULL; do { ++size; /* realloc buffer size until no overflow occurs */ if (NULL == (ifc.ifc_req = (ifreq*)realloc(ifc.ifc_req, IFRSIZE))) { fprintf(stderr, "Out of memory.\n"); exit(EXIT_FAILURE); } ifc.ifc_len = IFRSIZE; if (ioctl(g_NetworkSocket, SIOCGIFCONF, &ifc)) { perror("ioctl SIOCFIFCONF"); exit(EXIT_FAILURE); } } while (IFRSIZE <= ifc.ifc_len); ifr = ifc.ifc_req; for (;(char *) ifr < (char *) ifc.ifc_req + ifc.ifc_len; ++ifr) { if (ifr->ifr_addr.sa_data == (ifr+1)->ifr_addr.sa_data) { continue; /* duplicate, skip it */ } if (ioctl(g_NetworkSocket, SIOCGIFFLAGS, ifr)) { continue; /* failed to get flags, skip it */ } Printf("Found interface %s", ifr->ifr_name); Printf(" with IP address: %s\n", inet_ntoa(inaddrr(ifr_addr.sa_data))); *(int *)&Address.abIP = *(int *)&inaddrr(ifr_addr.sa_data); if ( Address.abIP[0] != 127 ) { Printf ( "Using IP address of interface %s as local address.\n", ifr->ifr_name ); break; } } if ( ifc.ifc_req != NULL ) free ( ifc.ifc_req ); #else struct ifreq *ifr; struct ifconf ifc; bzero(&ifc, sizeof(ifc)); unsigned int n = 1; struct ifreq *lifr; ifr = (ifreq*)calloc( ifc.ifc_len, sizeof(*ifr) ); do { n *= 2; ifr = (ifreq*)realloc( ifr, PAGE_SIZE * n ); bzero( ifr, PAGE_SIZE * n ); ifc.ifc_req = ifr; ifc.ifc_len = n * PAGE_SIZE; } while( ( ioctl( g_NetworkSocket, SIOCGIFCONF, &ifc ) == -1 ) || ( ifc.ifc_len >= ( (n-1) * PAGE_SIZE)) ); lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; while (ifr < lifr) { struct sockaddr *sa = &ifr->ifr_ifru.ifru_addr; if( AF_INET == sa->sa_family ) { struct sockaddr_in dummysa; in_addr inAddr = *(struct in_addr *) &ifr->ifr_addr.sa_data[sizeof dummysa.sin_port]; Printf("Found interface %s", ifr->ifr_name); Printf(" with IP address: %s\n", inet_ntoa(inAddr)); *(int *)&Address.abIP = *(int *)&inAddr; if ( Address.abIP[0] != 127 ) { Printf ( "Using IP address of interface %s as local address.\n", ifr->ifr_name ); break; } } ifr = (struct ifreq *)(((char *)ifr) + _SIZEOF_ADDR_IFREQ(*ifr)); } #endif } #endif Address.usPort = SocketAddress.sin_port; return ( Address ); }
void NETWORK_Construct( USHORT usPort, bool bAllocateLANSocket ) { char szString[128]; ULONG ulArg; USHORT usNewPort; bool bSuccess; // Initialize the Huffman buffer. HUFFMAN_Construct( ); #ifdef __WIN32__ // [BB] Linux doesn't know WSADATA, so this may not be moved outside the ifdef. WSADATA WSAData; if ( WSAStartup( 0x0101, &WSAData )) network_Error( "Winsock initialization failed!\n" ); Printf( "Winsock initialization succeeded!\n" ); #endif ULONG ulInAddr = INADDR_ANY; const char* pszIPAddress = Args->CheckValue( "-useip" ); // [BB] An IP was specfied. Check if it's valid and if it is, try to bind our socket to it. if ( pszIPAddress ) { ULONG requestedIP = inet_addr( pszIPAddress ); if ( requestedIP == INADDR_NONE ) { sprintf( szString, "NETWORK_Construct: %s is not a valid IP address\n", pszIPAddress ); network_Error( szString ); } else ulInAddr = requestedIP; } g_usLocalPort = usPort; // Allocate a socket, and attempt to bind it to the given port. g_NetworkSocket = network_AllocateSocket( ); // [BB] If we can't allocate a socket, sending / receiving net packets won't work. if ( g_NetworkSocket == INVALID_SOCKET ) network_Error( "NETWORK_Construct: Couldn't allocate socket. You will not be able to host or join servers.\n" ); else if ( network_BindSocketToPort( g_NetworkSocket, ulInAddr, g_usLocalPort, false ) == false ) { bSuccess = true; bool bSuccessIP = true; usNewPort = g_usLocalPort; while ( network_BindSocketToPort( g_NetworkSocket, ulInAddr, ++usNewPort, false ) == false ) { // Didn't find an available port. Oh well... if ( usNewPort == g_usLocalPort ) { // [BB] We couldn't use the specified IP, so just try any. if ( ulInAddr != INADDR_ANY ) { ulInAddr = INADDR_ANY; bSuccessIP = false; continue; } bSuccess = false; break; } } if ( bSuccess == false ) { sprintf( szString, "NETWORK_Construct: Couldn't bind socket to port: %d\n", g_usLocalPort ); network_Error( szString ); } else if ( bSuccessIP == false ) { sprintf( szString, "NETWORK_Construct: Couldn't bind socket to IP %s, using the default IP instead:\n", pszIPAddress ); network_Error( szString ); } else { Printf( "NETWORK_Construct: Couldn't bind to %d. Binding to %d instead...\n", g_usLocalPort, usNewPort ); g_usLocalPort = usNewPort; } } ulArg = true; if ( ioctlsocket( g_NetworkSocket, FIONBIO, &ulArg ) == -1 ) printf( "network_AllocateSocket: ioctl FIONBIO: %s", strerror( errno )); // If we're not starting a server, setup a socket to listen for LAN servers. if ( bAllocateLANSocket ) { g_LANSocket = network_AllocateSocket( ); if ( network_BindSocketToPort( g_LANSocket, ulInAddr, DEFAULT_BROADCAST_PORT, true ) == false ) { sprintf( szString, "network_BindSocketToPort: Couldn't bind LAN socket to port: %d. You will not be able to see LAN servers in the browser.", DEFAULT_BROADCAST_PORT ); network_Error( szString ); // [BB] The socket won't work in this case, make sure not to use it. g_bLANSocketInvalid = true; } if ( ioctlsocket( g_LANSocket, FIONBIO, &ulArg ) == -1 ) printf( "network_AllocateSocket: ioctl FIONBIO: %s", strerror( errno )); } // Init our read buffer. // [BB] Vortex Cortex pointed us to the fact that the smallest huffman code is only 3 bits // and it turns into 8 bits when it's decompressed. Thus we need to allocate a buffer that // can hold the biggest possible size we may get after decompressing (aka Huffman decoding) // the incoming UDP packet. NETWORK_InitBuffer( &g_NetworkMessage, ((MAX_UDP_PACKET * 8) / 3 + 1), BUFFERTYPE_READ ); NETWORK_ClearBuffer( &g_NetworkMessage ); // [BB] Get and save our local IP. if ( ( ulInAddr == INADDR_ANY ) || ( pszIPAddress == NULL ) ) g_LocalAddress = NETWORK_GetLocalAddress( ); // [BB] We are using a specified IP, so we don't need to figure out what IP we have, but just use the specified one. else { NETWORK_StringToAddress ( pszIPAddress, &g_LocalAddress ); g_LocalAddress.usPort = htons ( NETWORK_GetLocalPort() ); } // Print out our local IP address. Printf( "IP address %s\n", NETWORK_AddressToString( g_LocalAddress )); // If hosting, update the server GUI. if( NETWORK_GetState() == NETSTATE_SERVER ) SERVERCONSOLE_UpdateIP( g_LocalAddress ); // [BB] Initialize the checksum of the non-map lumps that need to be authenticated when connecting a new player. std::vector<std::string> lumpsToAuthenticate; std::vector<LumpAuthenticationMode> lumpsToAuthenticateMode; lumpsToAuthenticate.push_back( "COLORMAP" ); lumpsToAuthenticateMode.push_back( LAST_LUMP ); lumpsToAuthenticate.push_back( "PLAYPAL" ); lumpsToAuthenticateMode.push_back( LAST_LUMP ); lumpsToAuthenticate.push_back( "HTICDEFS" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "HEXNDEFS" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "STRFDEFS" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "DOOMDEFS" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "GLDEFS" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "DECORATE" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "LOADACS" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "DEHACKED" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); lumpsToAuthenticate.push_back( "GAMEMODE" ); lumpsToAuthenticateMode.push_back( ALL_LUMPS ); FString checksum, longChecksum; bool noProtectedLumpsAutoloaded = true; // [BB] All precompiled ACS libraries need to be authenticated. The only way to find all of them // at this point is to parse all LOADACS lumps. { int lump, lastlump = 0; while ((lump = Wads.FindLump ("LOADACS", &lastlump)) != -1) { FScanner sc(lump); while (sc.GetString()) { NETWORK_AddLumpForAuthentication ( Wads.CheckNumForName (sc.String, ns_acslibrary) ); } } } // [BB] First check the lumps that were marked for authentication while initializing. This // includes for example those lumps included by DECORATE lumps. It's much easier to mark those // lumps while the engine parses the DECORATE code than trying to find all included lumps from // the DECORATE lumps directly. for ( unsigned int i = 0; i < g_LumpNumsToAuthenticate.Size(); ++i ) { if ( !network_GenerateLumpMD5HashAndWarnIfNeeded( g_LumpNumsToAuthenticate[i], Wads.GetLumpFullName (g_LumpNumsToAuthenticate[i]), checksum ) ) noProtectedLumpsAutoloaded = false; longChecksum += checksum; } for ( unsigned int i = 0; i < lumpsToAuthenticate.size(); i++ ) { switch ( lumpsToAuthenticateMode[i] ){ case LAST_LUMP: int lump; lump = Wads.CheckNumForName(lumpsToAuthenticate[i].c_str()); // [BB] Possibly we find the COLORMAP lump only in the colormaps name space. if ( ( lump == -1 ) && ( lumpsToAuthenticate[i].compare ( "COLORMAP" ) == 0 ) ) lump = Wads.CheckNumForName("COLORMAP", ns_colormaps); if ( lump == -1 ) { Printf ( PRINT_BOLD, "Warning: Can't find lump %s for authentication!\n", lumpsToAuthenticate[i].c_str() ); continue; } if ( !network_GenerateLumpMD5HashAndWarnIfNeeded( lump, lumpsToAuthenticate[i].c_str(), checksum ) ) noProtectedLumpsAutoloaded = false; // [BB] To make Doom and Freedoom network compatible, substitue the Freedoom PLAYPAL/COLORMAP hash // by the corresponding Doom hash. // 4804c7f34b5285c334a7913dd98fae16 Doom PLAYPAL hash // 061a4c0f80aa8029f2c1bc12dc2e261e Doom COLORMAP hash // 2e01ae6258f2a0fdad32125537efe1af Freedoom PLAYPAL hash // bb535e66cae508e3833a5d2de974267b Freedoom COLORMAP hash if ( ( stricmp ( lumpsToAuthenticate[i].c_str(), "PLAYPAL" ) == 0 ) && ( stricmp ( checksum.GetChars(), "2e01ae6258f2a0fdad32125537efe1af" ) == 0 ) ) checksum = "4804c7f34b5285c334a7913dd98fae16"; else if ( ( stricmp ( lumpsToAuthenticate[i].c_str(), "COLORMAP" ) == 0 ) && ( stricmp ( checksum.GetChars(), "bb535e66cae508e3833a5d2de974267b" ) == 0 ) ) checksum = "061a4c0f80aa8029f2c1bc12dc2e261e"; longChecksum += checksum; break; case ALL_LUMPS: int workingLump, lastLump; lastLump = 0; while ((workingLump = Wads.FindLump(lumpsToAuthenticate[i].c_str(), &lastLump)) != -1) { if ( !network_GenerateLumpMD5HashAndWarnIfNeeded( workingLump, lumpsToAuthenticate[i].c_str(), checksum ) ) noProtectedLumpsAutoloaded = false; longChecksum += checksum; } break; } } CMD5Checksum::GetMD5( reinterpret_cast<const BYTE *>(longChecksum.GetChars()), longChecksum.Len(), g_lumpsAuthenticationChecksum ); // [BB] Warn the user about problematic auto-loaded files. if ( noProtectedLumpsAutoloaded == false ) { Printf ( PRINT_BOLD, "Warning: Above auto-loaded files contain protected lumps.\n" ); if ( Args->CheckParm( "-host" ) ) Printf ( PRINT_BOLD, "Clients without these files can't connect to this server.\n" ); else Printf ( PRINT_BOLD, "You can't connect to servers without these files.\n" ); } // [BB] Initialize the actor network class indices. for ( unsigned int i = 0; i < PClass::m_Types.Size(); i++ ) { PClass* cls = PClass::m_Types[i]; if ( (cls->IsDescendantOf(RUNTIME_CLASS(AActor))) // [BB] The server only binaries don't know DynamicLight and derived classes. && !(cls->IsDescendantOf(PClass::FindClass("DynamicLight"))) ) cls->ActorNetworkIndex = 1 + g_ActorNetworkIndexClassPointerMap.Push ( cls ); else cls->ActorNetworkIndex = 0; } // [RC/BB] Init the list of PWADs. network_InitPWADList( ); // Call NETWORK_Destruct() when Skulltag closes. atterm( NETWORK_Destruct ); Printf( "UDP Initialized.\n" ); }
BOOL CALLBACK main_ConnectDialogCallback( HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam ) { char szBuffer[128]; switch ( Message ) { case WM_CTLCOLORSTATIC: switch ( GetDlgCtrlID( (HWND) lParam )) { // Paint these two labels white. case IDC_INTROTEXT: case IDC_DESCTEXT: return (LRESULT) g_hWhiteBrush; // Ignore everything else. default: return NULL; } break; case WM_PAINT: { // Paint the top of the form white. PAINTSTRUCT Ps; RECT r; r.left = 0; r.top = 3; r.bottom = 55; r.right = 400; main_PaintRectangle( BeginPaint(hDlg, &Ps), &r, RGB(255, 255, 255)); } break; case WM_INITDIALOG: { g_hDlg = hDlg; // Load the icon. SendMessage( hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM) (HICON) LoadImage( g_hInst, MAKEINTRESOURCE( AAA_MAIN_ICON ), IMAGE_ICON, 16, 16, LR_SHARED )); SendMessage( hDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)LoadIcon( g_hInst, MAKEINTRESOURCE( AAA_MAIN_ICON ))); //============================== // Create the notification icon. //============================== ZeroMemory( &g_NotifyIconData, sizeof( g_NotifyIconData )); g_NotifyIconData.cbSize = sizeof( g_NotifyIconData ); g_NotifyIconData.hWnd = hDlg; g_NotifyIconData.uID = 0; g_NotifyIconData.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP; g_NotifyIconData.uCallbackMessage = UWM_TRAY_TRAYID; g_NotifyIconData.hIcon = (HICON) LoadImage( g_hInst, MAKEINTRESOURCE( AAA_MAIN_ICON ), IMAGE_ICON, 16, 16, LR_SHARED ); lstrcpy( g_NotifyIconData.szTip, g_szTooltip ); Shell_NotifyIcon( NIM_ADD, &g_NotifyIconData ); //================== // Create the menus. //================== // Create the favorites menu. g_hFavoritesMenu = CreatePopupMenu( ); int iIndex = 1; for( std::vector<FAVORITE_s>::iterator i = g_Favorites.begin(); i != g_Favorites.end(); ++i ) AppendMenu( g_hFavoritesMenu, MF_STRING, IDR_DYNAMIC_MENU + iIndex++, (LPCTSTR)(&(*i->szName)) ); // Create the tray menu. g_hTrayMenu = CreatePopupMenu( ); AppendMenu( g_hTrayMenu, MF_STRING, IDR_TOGGLE, "Show/Hide" ); AppendMenu( g_hTrayMenu, MF_STRING|MF_POPUP, (UINT)g_hFavoritesMenu, "Favorites"); AppendMenu( g_hTrayMenu, MF_SEPARATOR, 0, 0 ); AppendMenu( g_hTrayMenu, MF_STRING, IDR_EXIT, "Exit" ); // Create the file menu. HMENU hFileMenu = CreatePopupMenu( ); AppendMenu( hFileMenu, MF_STRING, IDR_EXIT, "Exit" ); // Create the file menu. HMENU hHelpMenu = CreatePopupMenu( ); AppendMenu( hHelpMenu, MF_STRING, IDR_ABOUT, "About..." ); // Create the main menu. g_hMainMenu = CreateMenu( ); AppendMenu( g_hMainMenu, MF_STRING|MF_POPUP, (UINT)hFileMenu, "File" ); AppendMenu( g_hMainMenu, MF_STRING|MF_POPUP, (UINT)g_hFavoritesMenu, "Favorites"); AppendMenu( g_hMainMenu, MF_STRING|MF_POPUP, (UINT)hHelpMenu, "Help"); AppendMenu( g_hMainMenu, MF_SEPARATOR, 0, 0 ); SetMenu( hDlg, g_hMainMenu ); // Set up the status bar. g_hDlgStatusBar = CreateStatusWindow( WS_CHILD | WS_VISIBLE, (LPCTSTR)NULL, hDlg, IDC_STATIC ); // Set up the top, white section. SendMessage( GetDlgItem( g_hDlg, IDC_INTROTEXT ), WM_SETFONT, (WPARAM) CreateFont( 13, 0, 0, 0, 600, 0, 0, 0, 0, 0, 0, 0, 0, "Tahoma" ), (LPARAM) 1 ); LOGBRUSH LogBrush; LogBrush.lbStyle = BS_SOLID; LogBrush.lbColor = RGB( 255, 255, 255 ); g_hWhiteBrush = CreateBrushIndirect( &LogBrush ); // Load the server address that was used last time. if ( g_Config.HaveSections( ) && g_Config.SetSection( "Settings", true ) && g_Config.GetValueForKey( "LastServer" ) ) SetDlgItemText( hDlg, IDC_SERVERIP, g_Config.GetValueForKey( "LastServer" ) ); } break; case WM_COMMAND: // Selecting a favorite from the menu? if ( LOWORD( wParam ) > IDR_DYNAMIC_MENU && LOWORD( wParam ) <= IDR_DYNAMIC_MENU + g_Favorites.size( )) { main_ConnectToFavorite( LOWORD( wParam ) - IDR_DYNAMIC_MENU - 1 ); return TRUE; } switch ( LOWORD( wParam )) { // This also occurs when esc is pressed. case IDCANCEL: if ( g_State == STATE_CONNECTING ) { main_SetState( STATE_WAITING ); main_EnableConnectionButtons( TRUE ); main_UpdateStatusbar( "Cancelled." ); } else main_Quit( ); break; // The "connect" button. case IDOK: // Disable all the inputs. main_EnableConnectionButtons( FALSE ); // Read in what the user gave us. GetDlgItemText( hDlg, IDC_SERVERIP, szBuffer, 128 ); NETWORK_StringToAddress( szBuffer, &g_ServerAddress ); GetDlgItemText( hDlg, IDC_PASSWORD, g_szPassword, 128 ); // If the user didn't specify a port, use the default one. if ( g_ServerAddress.usPort == 0 ) NETWORK_SetAddressPort( g_ServerAddress, DEFAULT_SERVER_PORT ); // Do some quick error checking. if ( !strlen( szBuffer )) MessageBox( hDlg, "You should probably enter a server address.", "Input error.", MB_ICONEXCLAMATION ); else if ( strlen( g_szPassword ) < 4 ) MessageBox( hDlg, "RCON passwords must be at least four characters long.", "Input error.", MB_ICONEXCLAMATION ); else { main_AttemptConnection( ); break; } // Re-enable the form so the user can try again. main_EnableConnectionButtons( TRUE ); break; case IDR_EXIT: main_Quit( ); break; case IDR_ABOUT: DialogBox( g_hInst, MAKEINTRESOURCE( IDD_ABOUTDIALOG ), hDlg, main_AboutDialogCallback ); break; } break; case WM_SYSCOMMAND: // Hide the window when minimized. if ( wParam == SC_MINIMIZE ) ShowWindow( hDlg, SW_HIDE ); else DefWindowProc( hDlg, Message, wParam, lParam ); break; case WM_CLOSE: main_Quit( ); break; case WM_DESTROY: Shell_NotifyIcon( NIM_DELETE, &g_NotifyIconData ); PostQuitMessage( 0 ); break; case UWM_TRAY_TRAYID: return main_TrayIconClicked( hDlg, lParam ); default: return FALSE; } return TRUE; }