1 2 3 /** 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 6 DO NOT CHANGE THIS FILE! 7 8 this file is deprecated and will be replaced with 9 10 lsl/networking/tasserver.h 11 12 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 **/ 14 15 16 #ifndef SPRINGLOBBY_HEADERGUARD_TASSERVER_H 17 #define SPRINGLOBBY_HEADERGUARD_TASSERVER_H 18 19 #include <wx/string.h> 20 #include <wx/longlong.h> 21 #include <wx/timer.h> 22 #include <list> 23 24 #include "server.h" 25 #include "crc.h" 26 27 const unsigned int FIRST_UDP_SOURCEPORT = 8300; 28 29 class Ui; 30 class Socket; 31 class User; 32 struct UserBattleStatus; 33 class IServerEvents; 34 class wxString; 35 class PingThread; 36 37 //! @brief TASServer protocol implementation. 38 class TASServer : public Server, public wxTimer 39 { 40 public: 41 TASServer(int serverEventsMode = 0); 42 ~TASServer(); 43 44 // Overloaded functions from Server 45 bool ExecuteSayCommand( const wxString& cmd ); 46 47 void SetSocket( Socket* sock ); 48 49 bool Register( const wxString& addr, const int port, const wxString& nick, const wxString& password,wxString& reason ); 50 void AcceptAgreement(); 51 52 void Connect( const wxString& servername, const wxString& addr, const int port ); 53 void Disconnect(); 54 bool IsConnected(); 55 56 void Login(); 57 void Logout(); 58 bool IsOnline() const; 59 60 void Update( int mselapsed ); 61 62 void Ping(); 63 64 void UDPPing();/// used for nat travelsal 65 /// generic udp "ping" function 66 /// return value: actual source port which was used. May differ from src_port 67 /// 0 if udp ping failed 68 unsigned int UdpPing(unsigned int src_port, const wxString &target, unsigned int target_port, const wxString &message); 69 /// specialized udp ping functions 70 void UdpPingTheServer( const wxString &message );/// used for nat travelsal. pings the server. 71 void UdpPingAllClients();/// used when hosting with nat holepunching 72 73 const User& GetMe() const; 74 User& GetMe(); 75 76 void JoinChannel( const wxString& channel, const wxString& key ); 77 void PartChannel( const wxString& channel ); 78 79 void DoActionChannel( const wxString& channel, const wxString& msg ); 80 void SayChannel( const wxString& channel, const wxString& msg ); 81 82 void DoActionPrivate( const wxString& nick, const wxString& msg ); 83 void SayPrivate( const wxString& nick, const wxString& msg ); 84 85 void SayBattle( int battleid, const wxString& msg ); 86 void DoActionBattle( int battleid, const wxString& msg ); 87 88 void Ring( const wxString& nick ); 89 90 void ModeratorSetChannelTopic( const wxString& channel, const wxString& topic ); 91 void ModeratorSetChannelKey( const wxString& channel, const wxString& key ); 92 void ModeratorMute( const wxString& channel, const wxString& nick, int duration, bool byip ); 93 void ModeratorUnmute( const wxString& channel, const wxString& nick ); 94 void ModeratorKick( const wxString& channel, const wxString& reason ); 95 void ModeratorBan( const wxString& nick, bool byip ); 96 void ModeratorUnban( const wxString& nick ); 97 void ModeratorGetIP( const wxString& nick ); 98 void ModeratorGetLastLogin( const wxString& nick ); 99 void ModeratorGetLastIP( const wxString& nick ); 100 void ModeratorFindByIP( const wxString& ipadress ); 101 102 void AdminGetAccountAccess( const wxString& nick ); 103 void AdminChangeAccountAccess( const wxString& nick, const wxString& accesscode ); 104 void AdminSetBotMode( const wxString& nick, bool isbot ); 105 106 void HostBattle( BattleOptions bo, const wxString& password = wxEmptyString ); 107 void JoinBattle( const int& battleid, const wxString& password = wxEmptyString ); 108 void LeaveBattle( const int& battleid ); 109 void SendMyBattleStatus( UserBattleStatus& bs ); 110 void SendMyUserStatus(); 111 112 void ForceSide( int battleid, User& user, int side ); 113 void ForceTeam( int battleid, User& user, int team ); 114 void ForceAlly( int battleid, User& user, int ally ); 115 void ForceColour( int battleid, User& user, const wxColour& col ); 116 void ForceSpectator( int battleid, User& user, bool spectator ); 117 void BattleKickPlayer( int battleid, User& user ); 118 void SetHandicap( int battleid, User& user, int handicap); 119 120 void AddBot( int battleid, const wxString& nick, UserBattleStatus& status ); 121 void RemoveBot( int battleid, User& bot ); 122 void UpdateBot( int battleid, User& bot, UserBattleStatus& status ); 123 124 void StartHostedBattle(); 125 void SendHostInfo( HostInfo update ); 126 void SendHostInfo( const wxString& Tag ); 127 void SendUserPosition( const User& user ); 128 129 void SendRaw( const wxString& raw ); 130 131 void RequestInGameTime( const wxString& nick ); 132 133 void SendUdpSourcePort( int udpport ); 134 void SendNATHelperInfos( const wxString& username, const wxString& ip, int port ); 135 136 Battle* GetCurrentBattle(); 137 138 void RequestChannels(); 139 // TASServer specific functions 140 void ExecuteCommand( const wxString& in ); 141 void ExecuteCommand( const wxString& cmd, const wxString& inparams, int replyid = -1 ); 142 143 void HandlePong( int replyid ); 144 145 void OnConnected( Socket* sock ); 146 void OnDisconnected( Socket* sock ); 147 void OnDataReceived( Socket* sock ); 148 149 bool IsPasswordHash( const wxString& pass ) const; 150 wxString GetPasswordHash( const wxString& pass ) const; 151 152 int TestOpenPort( unsigned int port ) const; 153 154 void SendScriptToProxy( const wxString& script ); 155 156 void SendScriptToClients( const wxString& script ); 157 158 void SetRelayIngamePassword( const User& user ); 159 160 wxArrayString GetRelayHostList() ; serverEvents()161 virtual const IServerEvents* serverEvents() const { return m_se; } 162 protected: 163 164 //! @brief Struct used internally by the TASServer class to calculate ping roundtimes. 165 struct TASPingListItem { 166 int id; 167 wxLongLong t; 168 }; 169 170 CRC m_crc; 171 172 IServerEvents* m_se; 173 double m_ser_ver; 174 175 wxString m_last_denied; 176 bool m_connected; 177 bool m_online; 178 bool m_debug_dont_catch; 179 bool m_id_transmission; 180 bool m_redirecting; 181 wxString m_buffer; 182 time_t m_last_udp_ping; 183 time_t m_last_ping; 184 time_t m_last_net_packet; 185 unsigned int m_last_id; 186 187 std::list<TASPingListItem> m_pinglist; 188 189 unsigned long m_udp_private_port; 190 unsigned long m_nat_helper_port; 191 192 int m_battle_id; 193 194 bool m_server_lanmode; 195 unsigned int m_account_id_count; 196 197 wxString m_agreement; 198 199 wxString m_addr; 200 wxString m_delayed_open_command; 201 202 bool m_do_finalize_join_battle; 203 int m_finalize_join_battle_id; 204 wxString m_finalize_join_battle_pw; 205 bool m_token_transmission; 206 207 void FinalizeJoinBattle(); 208 209 void SendCmd( const wxString& command, const wxString& param = wxEmptyString ); 210 void RelayCmd( const wxString& command, const wxString& param = wxEmptyString ); 211 212 wxString m_current_chan_name_mutelist; 213 214 wxArrayString m_relay_host_manager_list; 215 216 private: 217 void Notify(); 218 }; 219 220 #endif // SPRINGLOBBY_HEADERGUARD_TASSERVER_H 221 222 /** 223 This file is part of SpringLobby, 224 Copyright (C) 2007-2011 225 226 SpringLobby is free software: you can redistribute it and/or modify 227 it under the terms of the GNU General Public License version 2 as published by 228 the Free Software Foundation. 229 230 SpringLobby is distributed in the hope that it will be useful, 231 but WITHOUT ANY WARRANTY; without even the implied warranty of 232 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 233 GNU General Public License for more details. 234 235 You should have received a copy of the GNU General Public License 236 along with SpringLobby. If not, see <http://www.gnu.org/licenses/>. 237 **/ 238 239