LTBOOL CFolderJoin::DoJoinGame(CGameSpyServer* pGame) { // Sanity checks... if (!pGame) return(LTFALSE); if (g_pGameClientShell->IsInWorld() && g_pGameClientShell->GetGameType() != SINGLE) g_pInterfaceMgr->StartingNewGame(); // Get the ip address... char sIp[MAX_SGR_STRINGLEN] = { "" }; char* sTemp = pGame->GetAddress(); int port = pGame->GetIntValue("hostport",0); if (!sTemp) return(LTFALSE); sprintf(sIp, "%s:%d", sTemp, port); // Start the game... StartGameRequest req; NetClientData clientData; memset( &req, 0, sizeof( req )); // Setup our client... clientData.m_dwTeam = (uint32)GetConsoleInt("NetPlayerTeam",0); SAFE_STRCPY(clientData.m_sName,g_vtPlayerName.GetStr()); req.m_pClientData = &clientData; req.m_ClientDataLen = sizeof( clientData ); req.m_Type = STARTGAME_CLIENTTCP; strncpy( req.m_TCPAddress, sIp, MAX_SGR_STRINGLEN); // Try to join a game... int nType = DEATHMATCH; if (stricmp(pGame->GetGameType(), "H.A.R.M. vs. UNITY") == 0) nType = COOPERATIVE_ASSAULT; g_pGameClientShell->SetGameType((GameType)nType); g_pInterfaceMgr->DrawFragCount(LTFALSE); char szWorld[128]; sprintf(szWorld,"%s",pGame->GetMap()); HSTRING hWorld = g_pLTClient->CreateString(pGame->GetMap()); g_pInterfaceMgr->SetLoadLevelString(hWorld); g_pLTClient->FreeString(hWorld); g_pInterfaceMgr->ChangeState(GS_LOADINGLEVEL); char szPhoto[512] = "interface\\photos\\missions\\default.pcx"; if (nType == COOPERATIVE_ASSAULT) sprintf(szPhoto,"Worlds\\Multi\\AssaultMap\\%s.pcx",szWorld); else sprintf(szPhoto,"Worlds\\Multi\\DeathMatch\\%s.pcx",szWorld); g_pInterfaceMgr->SetLoadLevelPhoto(szPhoto); LTRESULT dr = g_pLTClient->InitNetworking(NULL, 0); if (dr != LT_OK) { // s_nErrorString = IDS_NETERR_INIT; // NetStart_DisplayError(hInst); g_pLTClient->CPrint("InitNetworking() : error %d", dr); return(LTFALSE); } int nRetries = GetConsoleInt("NetJoinRetry", 0); while (nRetries >= 0) { // If successful, then we're done. nConnectError = g_pLTClient->StartGame( &req ); if(nConnectError == LT_OK ) { return LTTRUE; } // Wait a sec and try again. Sleep(1000); nRetries--; } // All done... return(LTFALSE); }
// Change in focus void CFolderPlayer::OnFocus(LTBOOL bFocus) { if (bFocus) { m_bRestoreSkinHead = LTTRUE; m_nModNum = -1; m_nSkinNum = 0; m_nHeadNum = 0; int nUpdateRate = GetConsoleInt("UpdateRate",10); m_nConnect = 3; while (m_nConnect && nUpdateRate < kConnectSpeeds[m_nConnect]) m_nConnect--; nInitConnect = m_nConnect; SAFE_STRCPY(m_szPlayerModel,g_vtPlayerModel.GetStr() ); GetConsoleString("NetPlayerSkin",m_szPlayerSkin,""); GetConsoleString("NetPlayerHead",m_szPlayerHead,""); if ( !m_szPlayerSkin[0] || !m_szPlayerHead[0] ) { char szTemp[512]; strcpy(szTemp, m_szPlayerModel); if ( strchr(szTemp, ',') ) { *strchr(szTemp, ',') = '_'; _strlwr(szTemp); strcpy(m_szPlayerSkin, g_pModelButeMgr->GetButeMgr()->GetString(szTemp, "Skin0")); strcpy(m_szPlayerHead, g_pModelButeMgr->GetButeMgr()->GetString(szTemp, "Head0")); } } BuildModelList(); SAFE_STRCPY(m_szPlayerName,g_vtPlayerName.GetStr() ); if (m_nModNum < 0) { m_nModNum = 0; HSTRING hStr = m_pModelCtrl->GetString(0); strcpy(m_szPlayerModel,g_pLTClient->GetStringData(hStr)); } m_nTeam = (int)g_vtPlayerTeam.GetFloat(); m_nTargetNameSize = (int)g_vtTargetNameSize.GetFloat(); m_nTargetNameTransparency = (int)(100.0f*g_vtTargetNameTransparency.GetFloat()); m_bAutoSwitchWeapons = (LTBOOL)GetConsoleInt("AutoWeaponSwitch",1); m_bAutoSwitchAmmo = (LTBOOL)GetConsoleInt("AutoAmmoSwitch",1); m_bIgnoreTaunts = (LTBOOL)GetConsoleInt("IgnoreTaunts",0); UpdateData(LTFALSE); } else { UpdateData(); if (nInitConnect != m_nConnect) { WriteConsoleInt("UpdateRate",kConnectSpeeds[m_nConnect]); } LTBOOL bChanged = LTFALSE; char szTemp[32]; SAFE_STRCPY(szTemp,g_vtPlayerModel.GetStr() ); if (strcmp(szTemp,m_szPlayerModel) != 0) bChanged = LTTRUE; GetConsoleString("NetPlayerSkin",szTemp,""); if (strcmp(szTemp,m_szPlayerSkin) != 0) bChanged = LTTRUE; GetConsoleString("NetPlayerHead",szTemp,""); if (strcmp(szTemp,m_szPlayerHead) != 0) bChanged = LTTRUE; SAFE_STRCPY(szTemp,g_vtPlayerName.GetStr() ); if (strcmp(szTemp,m_szPlayerName) != 0) bChanged = LTTRUE; if (m_nTeam != (int)g_vtPlayerTeam.GetFloat()) bChanged = LTTRUE; g_vtPlayerName.SetStr(m_szPlayerName); g_vtPlayerModel.SetStr(m_szPlayerModel); WriteConsoleString("NetPlayerHead",m_szPlayerHead); WriteConsoleString("NetPlayerSkin",m_szPlayerSkin); g_vtPlayerTeam.WriteFloat((LTFLOAT)m_nTeam); g_vtTargetNameSize.WriteFloat((LTFLOAT)m_nTargetNameSize); g_vtTargetNameTransparency.WriteFloat((LTFLOAT)m_nTargetNameTransparency/100.0f); WriteConsoleInt("AutoWeaponSwitch",(int)m_bAutoSwitchWeapons); WriteConsoleInt("AutoAmmoSwitch",(int)m_bAutoSwitchAmmo); WriteConsoleInt("IgnoreTaunts",(int)m_bIgnoreTaunts); HLOCALOBJ hPlayerObj = g_pLTClient->GetClientObject(); if (bChanged && g_pGameClientShell->IsInWorld() && hPlayerObj && g_pGameClientShell->IsMultiplayerGame()) { HSTRING hstrName = g_pLTClient->CreateString(m_szPlayerName); if (!hstrName) return; HSTRING hstrModel = g_pLTClient->CreateString(m_szPlayerModel); if (!hstrModel) return; HSTRING hstrSkin = g_pLTClient->CreateString(strchr(m_szPlayerSkin, ',')+1); if (!hstrSkin) return; HSTRING hstrHead = g_pLTClient->CreateString(strchr(m_szPlayerHead, ',')+1); if (!hstrHead) return; // Init multiplayer info on server... HMESSAGEWRITE hWrite = g_pLTClient->StartMessage(MID_PLAYER_MULTIPLAYER_CHANGE); g_pLTClient->WriteToMessageHString(hWrite, hstrName); g_pLTClient->WriteToMessageHString(hWrite, hstrModel); g_pLTClient->WriteToMessageHString(hWrite, hstrSkin); g_pLTClient->WriteToMessageHString(hWrite, hstrHead); g_pLTClient->WriteToMessageByte(hWrite, (uint8)m_nTeam); g_pLTClient->EndMessage(hWrite); g_pLTClient->FreeString(hstrName); g_pLTClient->FreeString(hstrModel); g_pLTClient->FreeString(hstrSkin); g_pLTClient->FreeString(hstrHead); ClearModelList(); } g_pLTClient->FreeUnusedModels(); g_pLTClient->WriteConfigFile("autoexec.cfg"); } CBaseFolder::OnFocus(bFocus); }