Example #1
0
CRcon::CRcon(PCHAR szPassword, WORD wPort, WORD wMaxAdminCount, PCHAR szBindAddress)
{
	m_iCurrentAdminCount = 0;
	m_pRakServer = RakNetworkFactory::GetRakServerInterface();
	RegisterRPCs(m_pRakServer);
	m_pRakServer->SetPassword(szPassword);
	StartRconServer(szBindAddress, wPort, wMaxAdminCount);
}
Example #2
0
CNetGame::CNetGame ( )
{
	fRestartWaitTime = 0.0f;
	this->allowAdminTeleport = FALSE;
	this->allowInteriorWeapons = FALSE;
	this->worldTime = 12;
	this->weather	= 1;
	this->enableBonusStuntForAll = true;
	this->gravity	= 0.008f;
	this->deathDropAmount = 0;
	this->enableZoneName = false;
	
	this->playerPool = NULL;
	this->vehiclePool = NULL;
	this->gamemodeManager = NULL;
	this->pickupPool = NULL;
	this->objectPool = NULL;
	this->menuPool = NULL;
	this->textDrawPool = NULL;
	this->disableNameTagLineOfSight = true;
	this->gangZonePool = NULL;
	this->text3DLabelsPool = NULL;
	this->bLanMode = FALSE;
	this->byteMod = 0x01;

	this->blimitGlobalChatRadius = false;
	this->dlimitGlobalChatRadius = 10000.0f;
	this->bLimitPlayerMarkerRadius = FALSE;
	this->dlimitPlayerMarkerRadius = 10000.0f;
	this->nameTagDrawDistance = 70.0f;
	this->disableInteriorEnterExit = false;

	this->currentGameModeIndex = 0;
	this->currentGameModeRepeat = 0;
	this->isFirstGameModeLoad = FALSE;
	this->scriptTimerManager = new CScriptTimers;
	this->scriptHttpManager = new CScriptHttp;

	#ifndef WIN32
		this->elapsedTime = 0.0;
	#endif

	if(__Console->GetIntVar("maxplayers") > MAX_PLAYERS)
		__Console->SetIntVar("maxplayers", MAX_PLAYERS);

	char* szBindAddress = __Console->GetStringVar("bind");
	if (szBindAddress && szBindAddress[0] == 0)
		szBindAddress = NULL;

	uint16_t Port = __Console->GetIntVar("port");
	uint16_t MaxPlayers = __Console->GetIntVar("maxplayers");
	BOOL useLanMode = __Console->GetBoolVar("lanmode");

	this->rakServerInterface = RakNetworkFactory::GetRakServerInterface();
	
	//NetGameStartTime = RakNet::GetTime();

	if (!this->rakServerInterface->Start(MaxPlayers, 0, iServerSleepTimer, Port, szBindAddress))
	{
		if (szBindAddress)
			logprintf("Unable to start server on %s:%d. Port in use?",szBindAddress, Port);
		else
			logprintf("Unable to start server on port: %d. Port in use?", Port);
		return;
	}
	
	LoadBanList();

	if(!this->setNextGamemodeFile(NULL)) 
	{
		logprintf("I couldn't load any gamemode scripts. Please verify your server.cfg");
		logprintf("It needs a gamemode0 line at the very least.");
		fcloseall();
		exit(1);
	}
		
	this->rakServerInterface->StartOccasionalPing();

	char* szPass = __Console->GetStringVar("password");
	if ((szPass) && (szPass[0] != 0)) { 
		this->rakServerInterface->SetPassword(szPass);
	}

	RegisterRPCs(this->rakServerInterface);

	char szTime[256];
	sprintf(szTime, "%02d:%02d", this->worldTime, 0);
	__Console->AddStringVar("worldtime", CONSOLE_VARFLAG_RULE, szTime);
	
	if(useLanMode)
		this->bLanMode = true;

	char szScriptFiles[512];
	int len;

	#ifdef WIN32
		GetCurrentDirectoryA(sizeof(szScriptFiles), szScriptFiles);
		len = strlen(szScriptFiles);
		if (szScriptFiles[len-1] != '\\')
		{
			szScriptFiles[len] = '\\';
			szScriptFiles[len+1] = '\0';
		}
		strcat(szScriptFiles, "scriptfiles\\");
		SetEnvironmentVariableA("AMXFILE", szScriptFiles);
	#else
		getcwd(szScriptFiles, sizeof(szScriptFiles));
		len = strlen(szScriptFiles);
		if (szScriptFiles[len-1] != '/')
		{
			szScriptFiles[len] = '/';
			szScriptFiles[len+1] = '\0';
		}
		strcat(szScriptFiles, "scriptfiles/");
		setenv("AMXFILE", szScriptFiles, 1);
	#endif

	this->filterscriptsManager = new CFilterscriptsManager();

	if (szBindAddress) 
	{
		printf( "\nStarted server on %s:%d, with maxplayers: %d lanmode is %s.\n\n",
			szBindAddress, Port, MaxPlayers, useLanMode?"ON":"OFF" );
	}
	else
	{
		printf( "\nStarted server on port: %d, with maxplayers: %d lanmode is %s.\n\n",
			Port, MaxPlayers, useLanMode?"ON":"OFF" );
	}

	this->gameState = 0;
}
Example #3
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	srand((unsigned int)GetTickCount());

	// load up settings
	if(!LoadSettings())
	{
		Log("Failed to load settings");
		getchar();
		return 0;
	}

	if(settings.iConsole)
		SetUpConsole();
	else
	{
		SetUpWindow(hInstance);
		Sleep(500); // wait a bit for the dialog to create
	}

	// RCON mode
	if(settings.runMode == RUNMODE_RCON)
	{
		if(RCONReceiveLoop())
		{
			if(flLog != NULL)
			{
				fclose(flLog);
				flLog = NULL;
			}

			return 0;
		}
	}	

	// set up networking
	pRakClient = RakNetworkFactory::GetRakClientInterface();
	if(pRakClient == NULL)
		return 0;

	pRakClient->SetMTUSize(576);

	resetPools(1, 0);
	RegisterRPCs(pRakClient);

	SYSTEMTIME time;
	GetLocalTime(&time);
	if(settings.iConsole)
	{
		Log(" ");
		Log("* ===================================================== *");
		Log("  RakSAMP " RAKSAMP_VERSION " initialized on %02d/%02d/%02d %02d:%02d:%02d",
			time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute, time.wSecond);
		Log("  Authors: " AUTHOR "");
		Log("* ===================================================== *");
		Log(" ");
	}

	char szInfo[400];
	char szLastInfo[400];
	
	int iLastMoney = iMoney;
	int iLastDrunkLevel = iDrunkLevel;

	int iLastStatsUpdate = GetTickCount();
	
	while(1)
	{
		UpdateNetwork(pRakClient);

		if(settings.bSpam)
			sampSpam();

		if (settings.bFakeKill)
			sampFakeKill();

		if (settings.bLag)
			sampLag();

		if (settings.bJoinFlood)
			sampJoinFlood();

		if (settings.bChatFlood)
			sampChatFlood();

		if (settings.bClassFlood)
			sampClassFlood();

		processPulsator();
		processBulletFlood();

		if (!iConnectionRequested)
		{
			if(!iGettingNewName)
				sampConnect(settings.server.szAddr, settings.server.iPort, settings.server.szNickname, settings.server.szPassword, pRakClient);
			else
				sampConnect(settings.server.szAddr, settings.server.iPort, g_szNickName, settings.server.szPassword, pRakClient);

			iConnectionRequested = 1;
		}

		if (iAreWeConnected && iGameInited)
		{
			static DWORD dwLastInfoUpdate = GetTickCount();
			if(dwLastInfoUpdate && dwLastInfoUpdate < (GetTickCount() - 1000))
			{
				char szHealthText[16], szArmourText[16];

				if(settings.fPlayerHealth > 200.0f)
					sprintf_s(szHealthText, sizeof(szHealthText), "N/A");
				else
					sprintf_s(szHealthText, sizeof(szHealthText), "%.2f", settings.fPlayerHealth);

				if(settings.fPlayerArmour > 200.0f)
					sprintf_s(szArmourText, sizeof(szArmourText), "N/A");
				else
					sprintf_s(szArmourText, sizeof(szArmourText), "%.2f", settings.fPlayerArmour);

				sprintf_s(szInfo, 400, "Hostname: %s     Players: %d     Ping: %d     Authors: %s\nHealth: %s     Armour: %s     Skin: %d     X: %.4f     Y: %.4f     Z: %.4f     Rotation: %.4f",
				g_szHostName, getPlayerCount(), playerInfo[g_myPlayerID].dwPing, AUTHOR, szHealthText, szArmourText, iLocalPlayerSkin, settings.fNormalModePos[0], settings.fNormalModePos[1], settings.fNormalModePos[2], settings.fNormalModeRot);
				
				if(strcmp(szInfo, szLastInfo) != 0)
				{
					SetWindowText(texthwnd, szInfo);
					sprintf_s(szLastInfo, szInfo);
				}
			}

			if (settings.iUpdateStats)
			{
				if((GetTickCount() - iLastStatsUpdate >= 1000) || iMoney != iLastMoney || iDrunkLevel != iLastDrunkLevel)
				{
					RakNet::BitStream bsSend;

					bsSend.Write((BYTE)ID_STATS_UPDATE);

					iDrunkLevel -= (rand() % settings.iMaxFPS + settings.iMinFPS);

					if(iDrunkLevel < 0)
						iDrunkLevel = 0;

					bsSend.Write(iMoney);
					bsSend.Write(iDrunkLevel);

					pRakClient->Send(&bsSend, HIGH_PRIORITY, RELIABLE, 0);

					iLastMoney = iMoney;
					iLastDrunkLevel = iDrunkLevel;

					iLastStatsUpdate = GetTickCount();
				}
			}

			if(settings.runMode == RUNMODE_BARE)
				goto bare;

			if(!iSpawned)
			{
				if(settings.iManualSpawn != 0)
				{
					if(!iNotificationDisplayedBeforeSpawn)
					{
						sampRequestClass(settings.iClassID);
						
						Log("Please write !spawn into the console when you're ready to spawn.");

						iNotificationDisplayedBeforeSpawn = 1;
					}
				}
				else
				{
					sampRequestClass(settings.iClassID);
					sampSpawn();

					iSpawned = 1;
					iNotificationDisplayedBeforeSpawn = 1;
				}
			}
			else
			{
				if(settings.runMode == RUNMODE_STILL)
				{
					// Nothing left to do. :-)
				}

				if(settings.runMode == RUNMODE_NORMAL)
				{
					if(settings.AutoGotoCP && settings.CurrentCheckpoint.bActive)
					{
						settings.fNormalModePos[0] = settings.CurrentCheckpoint.fPosition[0];
						settings.fNormalModePos[1] = settings.CurrentCheckpoint.fPosition[1];
						settings.fNormalModePos[2] = settings.CurrentCheckpoint.fPosition[2];
					}

					onFootUpdateAtNormalPos();
				}

				// Run autorun commands
				if(settings.iAutorun)
				{
					if(dwAutoRunTick && dwAutoRunTick < (GetTickCount() - 2000))
					{
						static int autorun;
						if(!autorun)
						{
							Log("Loading autorun...");
							for(int i = 0; i < MAX_AUTORUN_CMDS; i++)
								if(settings.autoRunCMDs[i].iExists)
									RunCommand(settings.autoRunCMDs[i].szCMD, 1);

							autorun = 1;
						}
					}
				}

				// Following player mode.
				if(settings.runMode == RUNMODE_FOLLOWPLAYER)
				{
					PLAYERID copyingID = getPlayerIDFromPlayerName(settings.szFollowingPlayerName);
					if(copyingID != (PLAYERID)-1)
						onFootUpdateFollow(copyingID);
				}

				// Following a player with a vehicle mode.
				if(settings.runMode == RUNMODE_FOLLOWPLAYERSVEHICLE)
				{
					PLAYERID copyingID = getPlayerIDFromPlayerName(settings.szFollowingPlayerName);
					if(copyingID != (PLAYERID)-1)
						inCarUpdateFollow(copyingID, (VEHICLEID)settings.iFollowingWithVehicleID);
				}

			}
		}

bare:;
		Sleep(30);
	}

	if(flLog != NULL)
	{
		fclose(flLog);
		flLog = NULL;
	}

	if(flTextDrawsLog != NULL)
	{
		fclose(flTextDrawsLog);
		flTextDrawsLog = NULL;
	}

	return 0;
}
Example #4
0
CNetGame::CNetGame()
{
	fRestartWaitTime = 0.0f;
	m_bAdminTeleport = false;
	m_bAllowWeapons = FALSE;
	m_byteWorldTime = 12;
	m_byteWeather	= 10;
	m_bStuntBonus   = true;
	m_fGravity		= 0.008f;
	m_iDeathDropMoney = 0;
	m_bZoneNames = FALSE;
	
	m_longSynchedWeapons = DEFAULT_WEAPONS;
	// Change number here and in ShutdownForGameModeRestart for default weapon sets

	// Init member variables
	m_pPlayerPool = NULL;
	m_pVehiclePool = NULL;
	m_pGameMode = NULL;
	m_pPickupPool = NULL;
	m_pObjectPool = NULL;
	m_pMenuPool = NULL;
	m_pTextPool = NULL;
	m_pGangZonePool = NULL;
	m_bLanMode = FALSE;
	m_byteMod = 0x01;
	m_bACEnabled = pConsole->GetBoolVariable("anticheat");

	m_bLimitGlobalChatRadius = FALSE;
	m_fGlobalChatRadius = 10000.0f;
	m_fNameTagDrawDistance = 70.0f;
	m_bDisableEnterExits = false;

	m_iCurrentGameModeIndex = 0;
	m_iCurrentGameModeRepeat = 0;
	m_bFirstGameModeLoaded = FALSE;
	m_pScriptTimers = new CScriptTimers;
	
	#ifndef WIN32
		m_dElapsedTime = 0.0;
	#endif

	if(pConsole->GetIntVariable("maxplayers") > MAX_PLAYERS) {
		pConsole->SetIntVariable("maxplayers", MAX_PLAYERS);
	}

	CHAR *szBindAddress = pConsole->GetStringVariable("bind");
	if (szBindAddress && szBindAddress[0] == 0)
		szBindAddress = NULL;

	DWORD dwPort = pConsole->GetIntVariable("port");
	DWORD dwMaxPlayers = pConsole->GetIntVariable("maxplayers");
	BOOL bLanMode = pConsole->GetBoolVariable("lanmode");
	BOOL bMyriad = pConsole->GetBoolVariable("myriad");

	// Setup RakNet
	m_pRak = RakNetworkFactory::GetRakServerInterface();
	//m_pRak->InitializeSecurity(0, 0);
	//m_pRak->SetTrackFrequencyTable(true);

	if (!m_pRak->Start(dwMaxPlayers, 0, 10, dwPort, szBindAddress))
	{
		if (szBindAddress)
			logprintf("Unable to start server on %s:%d. Port in use?", 
							szBindAddress, dwPort);
		else
			logprintf("Unable to start server on port: %d. Port in use?", dwPort);
		return;
	}
	
	LoadBanList();

	if(!SetNextScriptFile(NULL)) {
		logprintf("I couldn't load any gamemode scripts. Please verify your server.cfg");
		logprintf("It needs a gamemode0 line at the very least.");
		fcloseall();
		exit(1);
	}
		
	m_pRak->StartOccasionalPing();
	//m_pRak->SetMTUSize(1492);

	char* szPass = pConsole->GetStringVariable("password");
	if ((szPass) && (szPass[0] != 0)) { 
		m_pRak->SetPassword(szPass);
	}

	// Register our RPC handlers
	RegisterRPCs(m_pRak);

	//if (IsACEnabled())
		//CAntiCheat::Initialize(this);

	char szTime[256];
	sprintf(szTime, "%02d:%02d", m_byteWorldTime, 0);
	pConsole->AddStringVariable("worldtime", CON_VARFLAG_RULE, szTime);

	if (bMyriad)
	{
		pConsole->SetStringVariable("mapname", "Myriad Islands");
		m_byteMod = 0x02;
	}
	
	// Define LAN mode
	if(bLanMode) {
		m_bLanMode = TRUE;
	}

	char szScriptFiles[512];
	int len;

	#ifdef WIN32
		GetCurrentDirectory(sizeof(szScriptFiles), szScriptFiles);
		len = strlen(szScriptFiles);
		if (szScriptFiles[len-1] != '\\')
		{
			szScriptFiles[len] = '\\';
			szScriptFiles[len+1] = '\0';
		}
		strcat(szScriptFiles, "scriptfiles\\");
		SetEnvironmentVariable("AMXFILE", szScriptFiles);
	#else
		getcwd(szScriptFiles, sizeof(szScriptFiles));
		len = strlen(szScriptFiles);
		if (szScriptFiles[len-1] != '/')
		{
			szScriptFiles[len] = '/';
			szScriptFiles[len+1] = '\0';
		}
		strcat(szScriptFiles, "scriptfiles/");
		setenv("AMXFILE", szScriptFiles, 1);
	#endif

	// Filterscripts are now entirely controlled from here, were all done from Gamemode before
	m_pFilterScripts = new CFilterScripts();
	
	if (szBindAddress) {
		printf( " Started Server on %s:%d, with maxplayers: %d lanmode is %s.\n",
			szBindAddress, dwPort, dwMaxPlayers, bLanMode?"ON":"OFF" );
	} else {
		printf( " Started Server on port: %d, with maxplayers: %d lanmode is %s.\n",
			dwPort, dwMaxPlayers, bLanMode?"ON":"OFF" );
	}

	m_iGameState = GAMESTATE_STOPPED;
}