Changeset View
Changeset View
Standalone View
Standalone View
network/NetClientTurnManager.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 36 Lines | |||||
{ | { | ||||
NETCLIENTTURN_LOG("PostCommand()\n"); | NETCLIENTTURN_LOG("PostCommand()\n"); | ||||
// Transmit command to server | // Transmit command to server | ||||
CSimulationMessage msg(m_Simulation2.GetScriptInterface(), m_ClientId, m_PlayerId, m_CurrentTurn + m_CommandDelay, data); | CSimulationMessage msg(m_Simulation2.GetScriptInterface(), m_ClientId, m_PlayerId, m_CurrentTurn + m_CommandDelay, data); | ||||
m_NetClient.SendMessage(&msg); | m_NetClient.SendMessage(&msg); | ||||
// Add to our local queue | // Add to our local queue | ||||
//AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + m_CommandDelay); | AddCommand(m_ClientId, m_PlayerId, data, m_CurrentTurn + m_CommandDelay); | ||||
// TODO: we should do this when the server stops sending our commands back to us | |||||
} | } | ||||
void CNetClientTurnManager::NotifyFinishedOwnCommands(u32 turn) | void CNetClientTurnManager::NotifyFinishedOwnCommands(u32 turn) | ||||
{ | { | ||||
NETCLIENTTURN_LOG("NotifyFinishedOwnCommands(%d)\n", turn); | NETCLIENTTURN_LOG("NotifyFinishedOwnCommands(%d)\n", turn); | ||||
CEndCommandBatchMessage msg; | CEndCommandBatchMessage msg; | ||||
Show All 33 Lines | void CNetClientTurnManager::OnDestroyConnection() | ||||
// Notice the sending is not reliable and rarely makes it to the Server. | // Notice the sending is not reliable and rarely makes it to the Server. | ||||
if (m_NetClient.GetCurrState() == NCS_INGAME) | if (m_NetClient.GetCurrState() == NCS_INGAME) | ||||
NotifyFinishedOwnCommands(m_CurrentTurn + m_CommandDelay); | NotifyFinishedOwnCommands(m_CurrentTurn + m_CommandDelay); | ||||
} | } | ||||
void CNetClientTurnManager::OnSimulationMessage(CSimulationMessage* msg) | void CNetClientTurnManager::OnSimulationMessage(CSimulationMessage* msg) | ||||
{ | { | ||||
// Command received from the server - store it for later execution | // Command received from the server - store it for later execution | ||||
AddCommand(msg->m_Client, msg->m_Player, msg->m_Data, msg->m_Turn); | AddCommand(msg->m_ClientId, msg->m_Player, msg->m_Data, msg->m_Turn); | ||||
} | } | ||||
void CNetClientTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, const std::vector<CSyncErrorMessage::S_m_PlayerNames>& playerNames) | void CNetClientTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, const std::vector<CSyncErrorMessage::S_m_PlayerNames>& playerNames) | ||||
{ | { | ||||
CStr expectedHashHex(Hexify(expectedHash)); | CStr expectedHashHex(Hexify(expectedHash)); | ||||
NETCLIENTTURN_LOG("OnSyncError(%d, %hs)\n", turn, expectedHashHex.c_str()); | NETCLIENTTURN_LOG("OnSyncError(%d, %hs)\n", turn, expectedHashHex.c_str()); | ||||
std::string hash; | std::string hash; | ||||
Show All 34 Lines |
Wildfire Games · Phabricator