From: <geo...@us...> - 2012-06-27 16:07:14
|
Revision: 4937 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4937&view=rev Author: geoffthemedio Date: 2012-06-27 16:07:04 +0000 (Wed, 27 Jun 2012) Log Message: ----------- -Added Diplomacy message type and event handlers to server. -grooming Modified Paths: -------------- trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/server/ServerFSM.cpp trunk/FreeOrion/server/ServerFSM.h Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2012-06-27 16:05:17 UTC (rev 4936) +++ trunk/FreeOrion/server/ServerApp.cpp 2012-06-27 16:07:04 UTC (rev 4937) @@ -254,6 +254,7 @@ case Message::COMBAT_TURN_ORDERS: m_fsm->process_event(CombatTurnOrders(msg, player_connection)); break; case Message::CLIENT_SAVE_DATA: m_fsm->process_event(ClientSaveData(msg, player_connection)); break; case Message::PLAYER_CHAT: m_fsm->process_event(PlayerChat(msg, player_connection)); break; + case Message::DIPLOMACY: m_fsm->process_event(Diplomacy(msg, player_connection)); break; case Message::REQUEST_NEW_OBJECT_ID: m_fsm->process_event(RequestObjectID(msg, player_connection)); break; case Message::REQUEST_NEW_DESIGN_ID: m_fsm->process_event(RequestDesignID(msg, player_connection)); break; Modified: trunk/FreeOrion/server/ServerFSM.cpp =================================================================== --- trunk/FreeOrion/server/ServerFSM.cpp 2012-06-27 16:05:17 UTC (rev 4936) +++ trunk/FreeOrion/server/ServerFSM.cpp 2012-06-27 16:07:04 UTC (rev 4937) @@ -123,8 +123,7 @@ m_server(server) {} -void ServerFSM::unconsumed_event(const sc::event_base &event) -{ +void ServerFSM::unconsumed_event(const sc::event_base &event) { std::string most_derived_message_type_str = "[ERROR: Unknown Event]"; const sc::event_base* event_ptr = &event; if (dynamic_cast<const Disconnection*>(event_ptr)) @@ -141,8 +140,7 @@ ServerApp& ServerFSM::Server() { return m_server; } -void ServerFSM::HandleNonLobbyDisconnection(const Disconnection& d) -{ +void ServerFSM::HandleNonLobbyDisconnection(const Disconnection& d) { PlayerConnectionPtr& player_connection = d.m_player_connection; int id = player_connection->PlayerID(); @@ -188,8 +186,7 @@ Idle::~Idle() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~Idle"; } -sc::result Idle::react(const HostMPGame& msg) -{ +sc::result Idle::react(const HostMPGame& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) Idle.HostMPGame"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -218,8 +215,7 @@ return transit<MPLobby>(); } -sc::result Idle::react(const HostSPGame& msg) -{ +sc::result Idle::react(const HostSPGame& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) Idle.HostSPGame"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -292,8 +288,7 @@ MPLobby::~MPLobby() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~MPLobby"; } -sc::result MPLobby::react(const Disconnection& d) -{ +sc::result MPLobby::react(const Disconnection& d) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) MPLobby.Disconnection"; ServerApp& server = Server(); PlayerConnectionPtr& player_connection = d.m_player_connection; @@ -376,8 +371,7 @@ } } -sc::result MPLobby::react(const JoinGame& msg) -{ +sc::result MPLobby::react(const JoinGame& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) MPLobby.JoinGame"; ServerApp& server = Server(); const SpeciesManager& sm = GetSpeciesManager(); @@ -465,8 +459,7 @@ } } -sc::result MPLobby::react(const LobbyUpdate& msg) -{ +sc::result MPLobby::react(const LobbyUpdate& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) MPLobby.LobbyUpdate"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -661,8 +654,7 @@ return discard_event(); } -sc::result MPLobby::react(const LobbyChat& msg) -{ +sc::result MPLobby::react(const LobbyChat& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) MPLobby.LobbyChat"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -679,8 +671,7 @@ return discard_event(); } -sc::result MPLobby::react(const StartMPGame& msg) -{ +sc::result MPLobby::react(const StartMPGame& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) MPLobby.StartMPGame"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -741,16 +732,14 @@ return transit<WaitingForMPGameJoiners>(); } -sc::result MPLobby::react(const HostMPGame& msg) -{ +sc::result MPLobby::react(const HostMPGame& msg) { Logger().errorStream() << "MPLobby::react(const HostMPGame& msg) recived HostMPGame message but is already in the MP Lobby. Aborting connection"; msg.m_player_connection->SendMessage(ErrorMessage("SERVER_ALREADY_HOSTING_GAME", true)); Server().m_networking.Disconnect(msg.m_player_connection); return discard_event(); } -sc::result MPLobby::react(const HostSPGame& msg) -{ +sc::result MPLobby::react(const HostSPGame& msg) { Logger().errorStream() << "MPLobby::react(const HostSPGame& msg) recived HostSPGame message but is already in the MP Lobby. Aborting connection"; msg.m_player_connection->SendMessage(ErrorMessage("SERVER_ALREADY_HOSTING_GAME", true)); Server().m_networking.Disconnect(msg.m_player_connection); @@ -851,8 +840,7 @@ WaitingForSPGameJoiners::~WaitingForSPGameJoiners() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~WaitingForSPGameJoiners"; } -sc::result WaitingForSPGameJoiners::react(const JoinGame& msg) -{ +sc::result WaitingForSPGameJoiners::react(const JoinGame& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForSPGameJoiners.JoinGame"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -903,8 +891,7 @@ return discard_event(); } -sc::result WaitingForSPGameJoiners::react(const CheckStartConditions& u) -{ +sc::result WaitingForSPGameJoiners::react(const CheckStartConditions& u) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForSPGameJoiners.CheckStartConditions"; ServerApp& server = Server(); @@ -934,8 +921,7 @@ return discard_event(); } -sc::result WaitingForSPGameJoiners::react(const LoadSaveFileFailed& u) -{ +sc::result WaitingForSPGameJoiners::react(const LoadSaveFileFailed& u) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForSPGameJoiners.LoadSaveFileFailed"; return transit<Idle>(); } @@ -981,8 +967,7 @@ WaitingForMPGameJoiners::~WaitingForMPGameJoiners() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~WaitingForMPGameJoiners"; } -sc::result WaitingForMPGameJoiners::react(const JoinGame& msg) -{ +sc::result WaitingForMPGameJoiners::react(const JoinGame& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForMPGameJoiners.JoinGame"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -1036,8 +1021,7 @@ return discard_event(); } -sc::result WaitingForMPGameJoiners::react(const CheckStartConditions& u) -{ +sc::result WaitingForMPGameJoiners::react(const CheckStartConditions& u) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForMPGameJoiners.CheckStartConditions"; ServerApp& server = Server(); @@ -1065,8 +1049,7 @@ PlayingGame::~PlayingGame() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~PlayingGame"; } -sc::result PlayingGame::react(const PlayerChat& msg) -{ +sc::result PlayingGame::react(const PlayerChat& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) PlayingGame.PlayerChat"; ServerApp& server = Server(); for (ServerNetworking::const_established_iterator it = server.m_networking.established_begin(); it != server.m_networking.established_end(); ++it) { @@ -1076,6 +1059,11 @@ return discard_event(); } +sc::result PlayingGame::react(const Diplomacy& msg) { + if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) PlayingGame.Diplomacy"; + ServerApp& server = Server(); + return discard_event(); +} //////////////////////////////////////////////////////////// // WaitingForTurnEnd @@ -1087,12 +1075,9 @@ } WaitingForTurnEnd::~WaitingForTurnEnd() -{ - if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~WaitingForTurnEnd"; -} +{ if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~WaitingForTurnEnd"; } -sc::result WaitingForTurnEnd::react(const TurnOrders& msg) -{ +sc::result WaitingForTurnEnd::react(const TurnOrders& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForTurnEnd.TurnOrders"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -1148,22 +1133,19 @@ return discard_event(); } -sc::result WaitingForTurnEnd::react(const RequestObjectID& msg) -{ +sc::result WaitingForTurnEnd::react(const RequestObjectID& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForTurnEnd.RequestObjectID"; Server().m_networking.SendMessage(DispatchObjectIDMessage(msg.m_message.SendingPlayer(), GetUniverse().GenerateObjectID())); return discard_event(); } -sc::result WaitingForTurnEnd::react(const RequestDesignID& msg) -{ +sc::result WaitingForTurnEnd::react(const RequestDesignID& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForTurnEnd.RequestDesignID"; Server().m_networking.SendMessage(DispatchDesignIDMessage(msg.m_message.SendingPlayer(), GetUniverse().GenerateDesignID())); return discard_event(); } -sc::result WaitingForTurnEnd::react(const CheckTurnEndConditions& c) -{ +sc::result WaitingForTurnEnd::react(const CheckTurnEndConditions& c) { ServerApp& server = Server(); if ((server.AllOrdersReceived() /* && minium_time_passed */) /* || maximum_time_passed*/) @@ -1190,8 +1172,7 @@ WaitingForTurnEndIdle::~WaitingForTurnEndIdle() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~WaitingForTurnEndIdle"; } -sc::result WaitingForTurnEndIdle::react(const SaveGameRequest& msg) -{ +sc::result WaitingForTurnEndIdle::react(const SaveGameRequest& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForTurnEndIdle.SaveGameRequest"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -1235,8 +1216,7 @@ WaitingForSaveData::~WaitingForSaveData() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~WaitingForSaveData"; } -sc::result WaitingForSaveData::react(const ClientSaveData& msg) -{ +sc::result WaitingForSaveData::react(const ClientSaveData& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) WaitingForSaveData.ClientSaveData"; ServerApp& server = Server(); const Message& message = msg.m_message; @@ -1334,8 +1314,7 @@ ProcessingTurn::~ProcessingTurn() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~ProcessingTurn"; } -sc::result ProcessingTurn::react(const ProcessTurn& u) -{ +sc::result ProcessingTurn::react(const ProcessTurn& u) { ServerApp& server = Server(); server.PreCombatProcessTurns(); server.ProcessCombats(); @@ -1377,8 +1356,7 @@ ProcessingTurnIdle::~ProcessingTurnIdle() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~ProcessingTurnIdle"; } -sc::result ProcessingTurnIdle::react(const ResolveCombat& u) -{ +sc::result ProcessingTurnIdle::react(const ResolveCombat& u) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ProcessingTurnIdle.ResolveCombat"; context<ProcessingTurn>().m_combat_system = u.m_system; @@ -1453,15 +1431,13 @@ std::cerr << "\n"; } -ResolvingCombat::~ResolvingCombat() -{ +ResolvingCombat::~ResolvingCombat() { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ~ResolvingCombat"; context<ProcessingTurn>().m_combat_empire_ids.clear(); } -sc::result ResolvingCombat::react(const CombatTurnOrders& msg) -{ +sc::result ResolvingCombat::react(const CombatTurnOrders& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ResolvingCombat.CombatTurnOrders"; ServerApp& server = Server(); @@ -1545,8 +1521,7 @@ return discard_event(); } -sc::result ResolvingCombat::react(const CombatComplete& cc) -{ +sc::result ResolvingCombat::react(const CombatComplete& cc) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) ResolvingCombat.CombatComplete"; ServerApp& server = Server(); delete server.m_current_combat; Modified: trunk/FreeOrion/server/ServerFSM.h =================================================================== --- trunk/FreeOrion/server/ServerFSM.h 2012-06-27 16:05:17 UTC (rev 4936) +++ trunk/FreeOrion/server/ServerFSM.h 2012-06-27 16:07:04 UTC (rev 4937) @@ -32,8 +32,7 @@ namespace sc = boost::statechart; // Non-Message events -struct Disconnection : sc::event<Disconnection> -{ +struct Disconnection : sc::event<Disconnection> { Disconnection(PlayerConnectionPtr& player_connection); PlayerConnectionPtr& m_player_connection; }; @@ -43,8 +42,7 @@ struct CheckTurnEndConditions : sc::event<CheckTurnEndConditions> {}; struct ProcessTurn : sc::event<ProcessTurn> {}; -struct ResolveCombat : sc::event<ResolveCombat> -{ +struct ResolveCombat : sc::event<ResolveCombat> { ResolveCombat(System* system, std::set<int>& empire_ids); System* const m_system; @@ -56,8 +54,7 @@ // Message events /** The base class for all state machine events that are based on Messages. */ -struct MessageEventBase -{ +struct MessageEventBase { MessageEventBase(Message& message, PlayerConnectionPtr& player_connection); ///< Basic ctor. Message m_message; @@ -78,7 +75,8 @@ (ClientSaveData) \ (RequestObjectID) \ (RequestDesignID) \ - (PlayerChat) + (PlayerChat) \ + (Diplomacy) #define DECLARE_MESSAGE_EVENT(r, data, name) \ @@ -119,8 +117,7 @@ #define SERVER_ACCESSOR private: ServerApp& Server() { return context<ServerFSM>().Server(); } /** The finite state machine that represents the server's operation. */ -struct ServerFSM : sc::state_machine<ServerFSM, Idle> -{ +struct ServerFSM : sc::state_machine<ServerFSM, Idle> { ServerFSM(ServerApp &server); void unconsumed_event(const sc::event_base &event); @@ -138,8 +135,7 @@ /** The server's initial state. */ -struct Idle : sc::state<Idle, ServerFSM> -{ +struct Idle : sc::state<Idle, ServerFSM> { typedef boost::mpl::list< sc::custom_reaction<HostMPGame>, sc::custom_reaction<HostSPGame> @@ -156,8 +152,7 @@ /** The server state in which the multiplayer lobby is active. */ -struct MPLobby : sc::state<MPLobby, ServerFSM> -{ +struct MPLobby : sc::state<MPLobby, ServerFSM> { typedef boost::mpl::list< sc::custom_reaction<Disconnection>, sc::custom_reaction<JoinGame>, @@ -189,8 +184,7 @@ /** The server state in which a new single-player game has been initiated, and * the server is waiting for all players to join. */ -struct WaitingForSPGameJoiners : sc::state<WaitingForSPGameJoiners, ServerFSM> -{ +struct WaitingForSPGameJoiners : sc::state<WaitingForSPGameJoiners, ServerFSM> { typedef boost::mpl::list< sc::in_state_reaction<Disconnection, ServerFSM, &ServerFSM::HandleNonLobbyDisconnection>, sc::custom_reaction<JoinGame>, @@ -219,8 +213,7 @@ /** The server state in which a multiplayer game has been initiated, and the * server is waiting for all players to join. */ -struct WaitingForMPGameJoiners : sc::state<WaitingForMPGameJoiners, ServerFSM> -{ +struct WaitingForMPGameJoiners : sc::state<WaitingForMPGameJoiners, ServerFSM> { typedef boost::mpl::list< sc::in_state_reaction<Disconnection, ServerFSM, &ServerFSM::HandleNonLobbyDisconnection>, sc::custom_reaction<JoinGame>, @@ -248,17 +241,18 @@ /** The server state in which a game has been started, and is actually being * played. */ -struct PlayingGame : sc::state<PlayingGame, ServerFSM, WaitingForTurnEnd> -{ +struct PlayingGame : sc::state<PlayingGame, ServerFSM, WaitingForTurnEnd> { typedef boost::mpl::list< sc::in_state_reaction<Disconnection, ServerFSM, &ServerFSM::HandleNonLobbyDisconnection>, - sc::custom_reaction<PlayerChat> + sc::custom_reaction<PlayerChat>, + sc::custom_reaction<Diplomacy> > reactions; PlayingGame(my_context c); ~PlayingGame(); sc::result react(const PlayerChat& msg); + sc::result react(const Diplomacy& msg); SERVER_ACCESSOR }; @@ -267,8 +261,7 @@ /** The substate of PlayingGame in which players are playing their turns and * the server is waiting for all players to finish their moves, after which * the server will process the turn. */ -struct WaitingForTurnEnd : sc::state<WaitingForTurnEnd, PlayingGame, WaitingForTurnEndIdle> -{ +struct WaitingForTurnEnd : sc::state<WaitingForTurnEnd, PlayingGame, WaitingForTurnEndIdle> { typedef boost::mpl::list< sc::custom_reaction<TurnOrders>, sc::custom_reaction<RequestObjectID>, @@ -291,8 +284,7 @@ /** The default substate of WaitingForTurnEnd. */ -struct WaitingForTurnEndIdle : sc::state<WaitingForTurnEndIdle, WaitingForTurnEnd> -{ +struct WaitingForTurnEndIdle : sc::state<WaitingForTurnEndIdle, WaitingForTurnEnd> { typedef boost::mpl::list< sc::custom_reaction<SaveGameRequest> > reactions; @@ -309,13 +301,13 @@ /** The substate of WaitingForTurnEnd in which a player has initiated a save * and the server is waiting for all players to send their save data, after * which the server will actually preform the save. */ -struct WaitingForSaveData : sc::state<WaitingForSaveData, WaitingForTurnEnd> -{ +struct WaitingForSaveData : sc::state<WaitingForSaveData, WaitingForTurnEnd> { typedef boost::mpl::list< sc::custom_reaction<ClientSaveData>, sc::deferral<SaveGameRequest>, sc::deferral<TurnOrders>, - sc::deferral<PlayerChat> + sc::deferral<PlayerChat>, + sc::deferral<Diplomacy> > reactions; WaitingForSaveData(my_context c); @@ -336,12 +328,12 @@ * executing orders, resolving combat, various steps in determining what * happens before and after combats occur, and updating players on changes in * the Universe. */ -struct ProcessingTurn : sc::state<ProcessingTurn, PlayingGame, ProcessingTurnIdle> -{ +struct ProcessingTurn : sc::state<ProcessingTurn, PlayingGame, ProcessingTurnIdle> { typedef boost::mpl::list< sc::custom_reaction<ProcessTurn>, sc::deferral<SaveGameRequest>, - sc::deferral<TurnOrders> + sc::deferral<TurnOrders>, + sc::deferral<Diplomacy> > reactions; ProcessingTurn(my_context c); @@ -357,8 +349,7 @@ /** The default substate of ProcessingTurn. */ -struct ProcessingTurnIdle : sc::state<ProcessingTurnIdle, ProcessingTurn> -{ +struct ProcessingTurnIdle : sc::state<ProcessingTurnIdle, ProcessingTurn> { typedef boost::mpl::list< sc::custom_reaction<ResolveCombat> > reactions; @@ -373,8 +364,7 @@ /** The substate of ProcessingTurn in which a single combat is resolved. */ -struct ResolvingCombat : sc::state<ResolvingCombat, ProcessingTurn> -{ +struct ResolvingCombat : sc::state<ResolvingCombat, ProcessingTurn> { typedef boost::mpl::list< sc::custom_reaction<CombatComplete>, sc::custom_reaction<CombatTurnOrders> |