/* Header NetworkConnectionCore Copyright (C) 2019 AleaJactaEst This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef STATE_CONNEXION_H #define STATE_CONNEXION_H #include "core/reference.h" #include "core/io/packet_peer_udp.h" #include "modules/bitset/bitset.h" #include "modules/bitstreamqueue/bitstreamqueue.h" #include "network_data.h" #include "modules/action/action.h" #define MAX_SIZE_BIT_STREAM_QUEUE 10 //define NUM_BITS_IN_LONG_ACK 512 enum STATE { NotInitialised = 0, //NotConnected = 1, // When received a cookie - not used here //Authenticate = 2, Login = 3, Synchronize = 4, Connected = 5, // State when we are connecte //Probe = 6, //Stalled = 7, Disconnect = 8, Quit = 9, ForceSynchronize = 10 }; enum CLFECOMMON { SYSTEM_LOGIN_CODE = 0, SYSTEM_SYNC_CODE = 1, SYSTEM_ACK_SYNC_CODE = 2, SYSTEM_PROBE_CODE = 3, SYSTEM_ACK_PROBE_CODE = 4, SYSTEM_DISCONNECTION_CODE = 5, SYSTEM_STALLED_CODE = 6, SYSTEM_SERVER_DOWN_CODE = 7, SYSTEM_QUIT_CODE = 8, SYSTEM_ACK_QUIT_CODE = 9, NUMBITSINLONGACK = 512 }; class NetworkConnectionCore; // Virtual class reference for network state class StateConnectionBase { protected: NetworkConnectionCore * _network; NetworkData * _data; public: StateConnectionBase(NetworkConnectionCore * network); ~StateConnectionBase() {} virtual int get_state() {return STATE::NotInitialised;} virtual void connect_to_server() {} virtual void send_message() {} //virtual void send_system_login() {} virtual void send_system_quit() {} virtual void send_system_disconnect() {} // virtual void send_system_ack_sync() {} virtual void receive_message(int index) {} virtual void send_system() {} }; // class define state not initialized class StateConnectionNotInitialized : public StateConnectionBase { public: StateConnectionNotInitialized(NetworkConnectionCore * network) : StateConnectionBase(network) {} ~StateConnectionNotInitialized() {} int get_state() {return STATE::NotInitialised;} void connect_to_server(); }; // class define state login class StateConnectionLogin : public StateConnectionBase { public: StateConnectionLogin(NetworkConnectionCore * network) : StateConnectionBase(network) {} ~StateConnectionLogin() {} int get_state() {return STATE::Login;} void send_system_quit(); void send_message(); }; // class define state synchronize class StateConnectionSynchronize : public StateConnectionBase { public: StateConnectionSynchronize(NetworkConnectionCore * network) : StateConnectionBase(network) {} ~StateConnectionSynchronize() {} int get_state() {return STATE::Synchronize;} void receive_system_sync(Ref msgin); void send_system_quit(); void send_system_ack_sync(); void receive_message(int index); void send_message(); }; // class define state connected class StateConnectionConnected : public StateConnectionBase { public: StateConnectionConnected(NetworkConnectionCore * network) : StateConnectionBase(network) {} ~StateConnectionConnected() {} int get_state() {return STATE::Connected;} void send_system_quit(); void send_system_disconnect(); void send_system_ack_sync(); void send_system_ack_probe(); void send_normal_message(); void receive_system_sync(Ref msgin); void receive_message(int index); void send_message(); }; // class define state quit class StateConnectionQuit : public StateConnectionBase { public: StateConnectionQuit(NetworkConnectionCore * network) : StateConnectionBase(network) {} ~StateConnectionQuit() {} int get_state() {return STATE::Quit;} }; #endif