示例#1
0
void SERVER_RCON_ParseMessage( NETADDRESS_s Address, LONG lMessage, BYTESTREAM_s *pByteStream )
{
	int iIndex = -1;

	switch ( lMessage )
	{
	case CLRC_BEGINCONNECTION:

		server_rcon_HandleNewConnection( Address, NETWORK_ReadByte( pByteStream ));
		break;
	case CLRC_PASSWORD:

		server_rcon_HandleLogin( server_rcon_FindCandidate( Address ), NETWORK_ReadString( pByteStream ));
		break;	
	case CLRC_PONG:

		iIndex = server_rcon_FindClient( Address );
		if ( iIndex != -1 )	
			g_AuthedClients[iIndex].iLastMessageTic = gametic;
		break;
	case CLRC_COMMAND:

		// Execute the command (if this came from an admin).
		iIndex = server_rcon_FindClient( Address );
		if ( iIndex != -1 )
		{
			const char *szCommand = NETWORK_ReadString( pByteStream );
			// [BB] Log the command before adding it. If we don't have a server GUI, the command
			// is executed immediately and may cause Skulltag to exit before the command is logged.
			Printf( "-> %s (RCON by %s)\n", szCommand, NETWORK_AddressToString( Address ) );
			SERVER_AddCommand( szCommand );
			g_AuthedClients[iIndex].iLastMessageTic = gametic;
		}
		break;
	case CLRC_DISCONNECT:
		
		iIndex = server_rcon_FindClient( Address );
		if ( iIndex != -1 )	
		{
			g_AuthedClients.Delete( iIndex );
			SERVER_RCON_UpdateInfo( SVRCU_ADMINCOUNT );
			Printf( "RCON client at %s disconnected.\n", NETWORK_AddressToString( Address ));
		}
		break;
	case CLRC_TABCOMPLETE:

		// [TP] RCON client wishes to tab-complete
		iIndex = server_rcon_FindClient( Address );
		if ( iIndex != -1 )
		{
			const char* part = NETWORK_ReadString( pByteStream );
			TArray<FString> list = C_GetTabCompletes( part );
			NETWORK_ClearBuffer( &g_MessageBuffer );

			// [TP] Let's not send too many of these though
			if ( list.Size() < 50 )
			{
				NETWORK_WriteByte( &g_MessageBuffer.ByteStream, SVRC_TABCOMPLETE );
				NETWORK_WriteByte( &g_MessageBuffer.ByteStream, list.Size() );

				for ( unsigned i = 0; i < list.Size(); ++i )
					NETWORK_WriteString( &g_MessageBuffer.ByteStream, list[i] );
			}
			else
			{
				NETWORK_WriteByte( &g_MessageBuffer.ByteStream, SVRC_TOOMANYTABCOMPLETES );
				NETWORK_WriteShort( &g_MessageBuffer.ByteStream, list.Size() );
			}

			NETWORK_LaunchPacket( &g_MessageBuffer, g_AuthedClients[iIndex].Address );
		}
		break;
	}
}
示例#2
0
void settings_Dialog_SaveSettings( )
{
	char	szBuffer[1024];
	FString fsRestartMessage = "";

	//==================================
	// Save the "server" tab's settings.
	//==================================

	HWND hDlg = g_hDlg_ServerTab;

	GetDlgItemText( hDlg, IDC_SERVERNAME, szBuffer, 1024 );
	sv_hostname = szBuffer;

	if ( g_ulNumPWADs > 0 )
	{
		GetDlgItemText( hDlg, IDC_WADURL, szBuffer, 1024 );
		sv_website = szBuffer;
	}

	GetDlgItemText( hDlg, IDC_EMAIL, szBuffer, 1024 );
	sv_hostemail = szBuffer;

	sv_updatemaster = !!SendDlgItemMessage( hDlg, IDC_UPDATEMASTER, BM_GETCHECK, 0, 0 );
	sv_broadcast = !!SendDlgItemMessage( hDlg, IDC_BROADCAST, BM_GETCHECK, 0, 0 );
	sv_motd = g_fsMOTD;

	//====================================
	// Save the "gameplay" tab's settings.
	//====================================

	hDlg = g_hDlg_GameplayTab;

	// Save limits.
	settings_Dialog_DoLimit( IDC_FRAGLIMIT,  fraglimit,   szBuffer );
	settings_Dialog_DoLimit( IDC_POINTLIMIT, pointlimit,  szBuffer );
	settings_Dialog_DoLimit( IDC_WINLIMIT,   winlimit,    szBuffer );
	settings_Dialog_DoLimit( IDC_DUELLIMIT,  duellimit,   szBuffer );
	settings_Dialog_DoLimit( IDC_MAXLIVES,   sv_maxlives, szBuffer );

	// Timelimit is a float.
	GetDlgItemText( hDlg, IDC_TIMELIMIT, szBuffer, 1024 );
	// [BB] We shouldn't compare two floats with "!=".
	if ( abs( timelimit - atof( szBuffer ) ) > 1e-8 )
		timelimit = atof( szBuffer );

	// Save game mode.
	if ( (LONG) GAMEMODE_GetCurrentMode( ) != SendDlgItemMessage( hDlg, IDC_GAMEPLAYMODE, CB_GETCURSEL, 0, 0 ))
	{
		fsRestartMessage += "Game mode\n";
		GAMEMODE_SetCurrentMode( (GAMEMODE_e) SendDlgItemMessage( hDlg, IDC_GAMEPLAYMODE, CB_GETCURSEL, 0, 0 ) );		
	}

	// Save modifier.
	if ( (LONG) GAMEMODE_GetModifier( ) != SendDlgItemMessage( hDlg, IDC_MODIFIER, CB_GETCURSEL, 0, 0 ))
	{
		fsRestartMessage += "Modifier\n";
		GAMEMODE_SetModifier( (MODIFIER_e) SendDlgItemMessage( hDlg, IDC_MODIFIER, CB_GETCURSEL, 0, 0 ) );
	}

	// Save skill.
	if ( SendDlgItemMessage( hDlg, IDC_SKILL, CB_GETCURSEL, 0, 0 ) != gameskill )
	{
		fsRestartMessage += "Skill\n";
		gameskill = SendDlgItemMessage( hDlg, IDC_SKILL, CB_GETCURSEL, 0, 0 );
	}

	// Save botskill.
	if ( SendDlgItemMessage( hDlg, IDC_BOTSKILL, CB_GETCURSEL, 0, 0 ) != botskill )
	{
		fsRestartMessage += "Bots' skill\n";
		botskill = SendDlgItemMessage( hDlg, IDC_BOTSKILL, CB_GETCURSEL, 0, 0 );
	}

	//====================================
	// Save the "admin" tab's settings.
	//====================================
	hDlg = g_hDlg_AdminTab;

	// Update logfile.
	GetDlgItemText( hDlg, IDC_LOGFILE, szBuffer, 256 );
	if ( stricmp( szBuffer, g_szDesiredLogFilename ) != 0 || sv_logfilenametimestamp != ( SendDlgItemMessage( hDlg, IDC_LOGFILENAME_TIMESTAMP, BM_GETCHECK, 0, 0 ) == BST_CHECKED ))
	{
		sv_logfilenametimestamp = ( SendDlgItemMessage( hDlg, IDC_LOGFILENAME_TIMESTAMP, BM_GETCHECK, 0, 0 ) == BST_CHECKED );

		if ( Logfile )
			StopLogging( );

		if ( SendDlgItemMessage( hDlg, IDC_ENABLELOGGING, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
			StartLogging( szBuffer );
	}

	GetDlgItemText( hDlg, IDC_RCONPASSWORD, szBuffer, 1024 );
	sv_rconpassword = ( SendDlgItemMessage( hDlg, IDC_ALLOWRCON, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) ? szBuffer : "";

	//==================================
	// Save the "access" tab's settings.
	//==================================

	hDlg = g_hDlg_AccessTab;

	// Save voting settings.
	if ( SendDlgItemMessage( hDlg, IDC_ALLOW_CALLVOTE, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
	{
		if ( SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_SPECTATOR, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
			sv_nocallvote = 0;
		else
			sv_nocallvote = 2;
	}
	else
		sv_nocallvote = 1;

	sv_noduellimitvote = !SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_DUELLIMIT, BM_GETCHECK, 0, 0 );
	sv_nofraglimitvote = !SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_FRAGLIMIT, BM_GETCHECK, 0, 0 );
	sv_nokickvote = !SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_KICKLIMIT, BM_GETCHECK, 0, 0 );
	sv_nopointlimitvote = !SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_POINTLIMIT, BM_GETCHECK, 0, 0 );
	sv_notimelimitvote = !SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_TIMELIMIT, BM_GETCHECK, 0, 0 );
	sv_nowinlimitvote = !SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_WINLIMIT, BM_GETCHECK, 0, 0 );
	sv_nomapvote = !SendDlgItemMessage( hDlg, IDC_ALLOWVOTE_MAP, BM_GETCHECK, 0, 0 );

	GetDlgItemText( hDlg, IDC_PASSWORD, szBuffer, 1024 );
	sv_password = szBuffer;
	sv_forcepassword = !!SendDlgItemMessage( hDlg, IDC_REQUIREPW, BM_GETCHECK, 0, 0 );

	GetDlgItemText( hDlg, IDC_JOINPASSWORD, szBuffer, 1024 );
	sv_joinpassword = szBuffer;
	sv_forcejoinpassword = !!SendDlgItemMessage( hDlg, IDC_REQUIREJOINPW, BM_GETCHECK, 0, 0 );

	GetDlgItemText( hDlg, IDC_MAXCLIENTS, szBuffer, 1024 );
	sv_maxclients = atoi( szBuffer );

	GetDlgItemText( hDlg, IDC_MAXPLAYERS, szBuffer, 1024 );
	sv_maxplayers = atoi( szBuffer );

	// Is a map change needed?
	if ( fsRestartMessage.Len( ))
	{
		fsRestartMessage = "The following settings require a map change to take effect:\n\n" + fsRestartMessage + "\nRestart the map?";
		if ( MessageBox( g_hDlg_Dialog, fsRestartMessage.GetChars( ), SERVERCONSOLE_TITLESTRING, MB_YESNO|MB_ICONQUESTION ) == IDYES )
		{
			FString String;
			String.Format( "map %s", level.mapname );	
			SERVER_AddCommand( String.GetChars( ));
		}
	}

	// Update our 'public/private/LAN' section in the statusbar.
	SERVERCONSOLE_UpdateBroadcasting( );
}