void inCarUpdateFollow(PLAYERID followID, VEHICLEID withVehicleID) { if(playerInfo[g_myPlayerID].iAreWeInAVehicle) { INCAR_SYNC_DATA icSync; memset(&icSync, 0, sizeof(INCAR_SYNC_DATA)); icSync.VehicleID = withVehicleID; SendInCarFullSyncData(&icSync, 0, followID); AIM_SYNC_DATA aimSync; memset(&aimSync, 0, sizeof(AIM_SYNC_DATA)); SendAimSyncData(&aimSync, 0, 0, followID); } if(inCarUpdateTick && inCarUpdateTick < (GetTickCount() - 10000)) { if(!playerInfo[g_myPlayerID].iAreWeInAVehicle) { if(playerInfo[followID].incarData.VehicleID == (VEHICLEID)-1) return; SendEnterVehicleNotification((VEHICLEID)settings.iFollowingWithVehicleID, 0); playerInfo[g_myPlayerID].iAreWeInAVehicle = 1; inCarUpdateTick = 0; } inCarUpdateTick = GetTickCount(); } else { if(!playerInfo[g_myPlayerID].iAreWeInAVehicle) onFootUpdateFollow(followID); } }
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; }