diff options
Diffstat (limited to 'tsclient.h')
| -rw-r--r-- | tsclient.h | 489 |
1 files changed, 489 insertions, 0 deletions
diff --git a/tsclient.h b/tsclient.h new file mode 100644 index 0000000..ccc32b0 --- /dev/null +++ b/tsclient.h | |||
| @@ -0,0 +1,489 @@ | |||
| 1 | /* | ||
| 2 | * This program is free software; you can redistribute it and/or modify | ||
| 3 | * it under the terms of the GNU General Public License as published by | ||
| 4 | * the Free Software Foundation; version 2 of the License. | ||
| 5 | * | ||
| 6 | * This program is distributed in the hope that it will be useful, | ||
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 9 | * GNU General Public License for more details. | ||
| 10 | * | ||
| 11 | * You should have received a copy of the GNU General Public License | ||
| 12 | * along with this program; if not, write to the Free Software | ||
| 13 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 14 | * | ||
| 15 | * Authors: Manuel Mausz (manuel@mausz.at) | ||
| 16 | * Christian Raschko (c.raschko@netcore.at) | ||
| 17 | */ | ||
| 18 | |||
| 19 | //Header guard | ||
| 20 | #ifndef TSCLIENT_H | ||
| 21 | #define TSCLIENT_H | ||
| 22 | |||
| 23 | //Libraries | ||
| 24 | #include <wx/wx.h> | ||
| 25 | #include <wx/thread.h> | ||
| 26 | |||
| 27 | #include "tsheaders.h" | ||
| 28 | #include "tsserver.h" | ||
| 29 | |||
| 30 | //! Thread response timeout | ||
| 31 | #define THREAD_TIMEOUT 4000 | ||
| 32 | |||
| 33 | //! Maximum time to leave | ||
| 34 | #define MAX_TTL 5 | ||
| 35 | |||
| 36 | // better than void * | ||
| 37 | union TSPtr | ||
| 38 | { | ||
| 39 | TSPlayer *pPlayer; | ||
| 40 | TSChannel *pChannel; | ||
| 41 | TSServer *pServer; | ||
| 42 | TSClient *pClient; | ||
| 43 | wxString *pString; | ||
| 44 | }; | ||
| 45 | |||
| 46 | //! Only for internal use | ||
| 47 | struct TSCmd : wxObject | ||
| 48 | { | ||
| 49 | DECLARE_CLASS(TSCmd) | ||
| 50 | //CTor | ||
| 51 | TSCmd() | ||
| 52 | { | ||
| 53 | id = 0; | ||
| 54 | executed = false; | ||
| 55 | error = false; | ||
| 56 | ttl = MAX_TTL; | ||
| 57 | pktid = 0; | ||
| 58 | oldid = 0; | ||
| 59 | client = NULL; | ||
| 60 | param1.pPlayer = NULL; | ||
| 61 | param1.pPlayer = NULL; | ||
| 62 | } | ||
| 63 | |||
| 64 | TSCmd(wxUint32 c) | ||
| 65 | { | ||
| 66 | TSCmd(); | ||
| 67 | id = c; | ||
| 68 | } | ||
| 69 | |||
| 70 | TSCmd(wxUint32 c, TSCmd *old) | ||
| 71 | { | ||
| 72 | TSCmd(); | ||
| 73 | id = c; | ||
| 74 | pktid = old->pktid; | ||
| 75 | oldid = old->id; | ||
| 76 | client = old->client; | ||
| 77 | } | ||
| 78 | |||
| 79 | TSCmd(const TSCmd &cmd) | ||
| 80 | : wxObject() | ||
| 81 | { | ||
| 82 | id = cmd.id; | ||
| 83 | oldid = cmd.oldid; | ||
| 84 | executed = cmd.executed; | ||
| 85 | error = cmd.error; | ||
| 86 | ttl = cmd.ttl; | ||
| 87 | pktid = cmd.pktid; | ||
| 88 | client = cmd.client; | ||
| 89 | param1 = cmd.param1; | ||
| 90 | param2 = cmd.param2; | ||
| 91 | lasterror = cmd.lasterror; | ||
| 92 | } | ||
| 93 | |||
| 94 | wxUint32 id; | ||
| 95 | wxUint32 oldid; | ||
| 96 | bool executed; | ||
| 97 | bool error; | ||
| 98 | wxUint32 ttl; | ||
| 99 | wxUint32 pktid; | ||
| 100 | TSClient *client; | ||
| 101 | TSPtr param1; | ||
| 102 | TSPtr param2; | ||
| 103 | wxString lasterror; | ||
| 104 | }; | ||
| 105 | |||
| 106 | //! TeamSpeak client, main class. | ||
| 107 | /*! TSClient is the main class to connect to a | ||
| 108 | * TeamSpeak server. These stepps are necessary | ||
| 109 | * to create and use a TSClient object. | ||
| 110 | * - Create a TSClient object. | ||
| 111 | * - Change the attributes. | ||
| 112 | * - Create a TSPlayer object. | ||
| 113 | * - Change the attributes. | ||
| 114 | * - Link it to the TSClient object. | ||
| 115 | * - Create a TSServer object. | ||
| 116 | * - Change the attributes. | ||
| 117 | * - Link it to the TSClient object. | ||
| 118 | * - Call Connect(). | ||
| 119 | * | ||
| 120 | * Example: | ||
| 121 | * \code | ||
| 122 | * | ||
| 123 | * TSClient *pTSC = new TSClient; | ||
| 124 | * pTSC->SetPlatform(_T("Windows XP")); | ||
| 125 | * pTSC->SetVersionNumber(_T("2.0.32.60")); | ||
| 126 | * | ||
| 127 | * TSPlayer *pTSP = new TSPlayer; | ||
| 128 | * pTSP->SetLoginName(_T("admin")); | ||
| 129 | * pTSP->SetLoginPassword(_T("testpassword")); | ||
| 130 | * pTSP->SetNickname(_T("penner")); | ||
| 131 | * //now the TSClient takes care of the pointer. | ||
| 132 | * pTSC->SetPlayer(pTSP); | ||
| 133 | * | ||
| 134 | * TSServer *pTSS = new TSServer; | ||
| 135 | * pTSS->SetServerAddress(_T("game3.clan-server.at")); | ||
| 136 | * pTSS->SetPort(8767); | ||
| 137 | * //now the TSClient takes care of the pointer. | ||
| 138 | * pTSC->SetServer(pTSS); | ||
| 139 | * | ||
| 140 | * if(!pTSC->Connect()) | ||
| 141 | * { | ||
| 142 | * wxLogError(_T("%s, terminating.\n"), pTSC->GetLastError().c_str()); | ||
| 143 | * return EXIT_FAILURE; | ||
| 144 | * } | ||
| 145 | * | ||
| 146 | * pTSC->Disconnect(); | ||
| 147 | * delete pTSC; | ||
| 148 | * \endcode | ||
| 149 | */ | ||
| 150 | class TSClient : public wxObject | ||
| 151 | { | ||
| 152 | DECLARE_CLASS(TSClient) | ||
| 153 | |||
| 154 | public: | ||
| 155 | |||
| 156 | /*! Default CTor, Initializes the object. | ||
| 157 | * Creates all necessary member objects. | ||
| 158 | */ | ||
| 159 | TSClient(); | ||
| 160 | |||
| 161 | /*! Default DTor. | ||
| 162 | */ | ||
| 163 | ~TSClient(); | ||
| 164 | |||
| 165 | /*! Connects to a Teasmpeak server. | ||
| 166 | * \return Returns false if fails, check GetLastError for details. | ||
| 167 | * \sa GetLastError() | ||
| 168 | */ | ||
| 169 | bool Connect(); | ||
| 170 | |||
| 171 | /*! Disconnects from a Teasmpeak server. | ||
| 172 | * \return Returns false if fails, check GetLastError for details. | ||
| 173 | * \sa GetLastError() | ||
| 174 | */ | ||
| 175 | bool Disconnect(bool reconnect = true); | ||
| 176 | |||
| 177 | /*! Sets the platform string (e.g. Windows XP, Linux). | ||
| 178 | * \param str Platform string. | ||
| 179 | * \return Returns false if fails, check GetLastError for details. | ||
| 180 | * \sa GetLastError() | ||
| 181 | */ | ||
| 182 | bool SetPlatform(wxString const &str); | ||
| 183 | |||
| 184 | /*! Sets the TeamSpeak player. | ||
| 185 | * The class takes care of the pointer, no delete call. | ||
| 186 | * \param pPlayer TeamSpeak Player. | ||
| 187 | * \return Returns false if fails, check GetLastError for details. | ||
| 188 | * \sa TSPlayer GetLastError() | ||
| 189 | */ | ||
| 190 | bool SetPlayer(TSPlayer *pPlayer); | ||
| 191 | |||
| 192 | /*! Sets the TeamSpeak player channel. | ||
| 193 | * The class takes care of the pointer, no delete call. | ||
| 194 | * \param pChannel player channel. | ||
| 195 | * \return Returns false if fails, check GetLastError for details. | ||
| 196 | * \sa TSChannel GetLastError() | ||
| 197 | */ | ||
| 198 | bool SetChannel(TSChannel *pChannel); | ||
| 199 | |||
| 200 | /*! Sets the TeamSpeak server. | ||
| 201 | * The class takes care of the pointer, no delete call. | ||
| 202 | * \param pServer Server to use for connection. | ||
| 203 | * \return Returns false if fails, check GetLastError for details. | ||
| 204 | * \sa TSServer GetLastError() | ||
| 205 | */ | ||
| 206 | bool SetServer(TSServer *pServer); | ||
| 207 | |||
| 208 | /*! Sets the TeamSpeak connection. | ||
| 209 | * The class takes care of the pointer, no delete call. | ||
| 210 | * \param pConnection Connection object. | ||
| 211 | * \return Returns false if fails, check GetLastError for details. | ||
| 212 | * \sa TSConnection GetLastError() | ||
| 213 | */ | ||
| 214 | bool SetConnection(TSConnectionThread *pConnection); | ||
| 215 | |||
| 216 | /*! Sets the TeamSpeak client version number (e.g. "2.0.32.60"). | ||
| 217 | * \param str Client version number. | ||
| 218 | * \return Returns false if fails, check GetLastError for details. | ||
| 219 | * \sa TSConnection GetLastError() | ||
| 220 | */ | ||
| 221 | bool SetVersionNumber(wxString const &str); | ||
| 222 | |||
| 223 | /*! Sets the session id. | ||
| 224 | * \param id Session id. | ||
| 225 | * \return Returns false if fails, check GetLastError for details. | ||
| 226 | * \sa GetLastError() | ||
| 227 | */ | ||
| 228 | bool SetSessionId(wxUint32 const id); | ||
| 229 | |||
| 230 | /*! Check if connected. | ||
| 231 | * \return Returns true if connected. | ||
| 232 | * \sa GetLastError() | ||
| 233 | */ | ||
| 234 | bool IsConnected(); | ||
| 235 | |||
| 236 | /*! Returns the state of the reconnectflag | ||
| 237 | * \return Returns false if fails, check GetLastError for details. | ||
| 238 | * \sa GetLastError() | ||
| 239 | */ | ||
| 240 | bool IsReconnectActive() | ||
| 241 | { | ||
| 242 | return m_pReconnectAct; | ||
| 243 | } | ||
| 244 | |||
| 245 | /*! Sets Sync onject, for thread sync. | ||
| 246 | * \param sync Sync onject. | ||
| 247 | * \return Returns false if fails, check GetLastError for details. | ||
| 248 | * \sa GetLastError() | ||
| 249 | */ | ||
| 250 | bool SetSync(TSCmd *sync); | ||
| 251 | |||
| 252 | /*! Gets the TeamSpeak client Platform string. | ||
| 253 | * \return Client Platform string. | ||
| 254 | */ | ||
| 255 | wxString const &GetPlatform() const | ||
| 256 | { | ||
| 257 | return m_Platform; | ||
| 258 | } | ||
| 259 | |||
| 260 | /*! Gets the LastError message, call this method | ||
| 261 | * to get more information for an error. | ||
| 262 | * \return LastError message. | ||
| 263 | */ | ||
| 264 | wxString const &GetLastError() const | ||
| 265 | { | ||
| 266 | return m_LastError; | ||
| 267 | } | ||
| 268 | |||
| 269 | /*! Gets the version number | ||
| 270 | * \return Version number. | ||
| 271 | */ | ||
| 272 | wxString const &GetVersionNumber() const | ||
| 273 | { | ||
| 274 | return m_VersionNumber; | ||
| 275 | } | ||
| 276 | |||
| 277 | /*! Gets the TeamSpeak player. | ||
| 278 | * \return TeamSpeak player. | ||
| 279 | * \sa TSPlayer | ||
| 280 | */ | ||
| 281 | TSPlayer *GetPlayer() const | ||
| 282 | { | ||
| 283 | return m_pPlayer; | ||
| 284 | } | ||
| 285 | |||
| 286 | /*! Gets all TeamSpeak players on the server. | ||
| 287 | * \return TeamSpeak players. | ||
| 288 | * \sa TSPlayer | ||
| 289 | */ | ||
| 290 | TSpPlayerArray *GetPlayers() const | ||
| 291 | { | ||
| 292 | return m_ppPlayers; | ||
| 293 | } | ||
| 294 | |||
| 295 | /*! Gets the TeamSpeak channel. | ||
| 296 | * \return TeamSpeak channel. | ||
| 297 | * \sa TSChannel | ||
| 298 | */ | ||
| 299 | TSChannel *GetChannel() const | ||
| 300 | { | ||
| 301 | return m_pChannel; | ||
| 302 | } | ||
| 303 | |||
| 304 | /*! Gets all TeamSpeak channels on the server. | ||
| 305 | * \return TeamSpeak channels. | ||
| 306 | * \sa TSChannel | ||
| 307 | */ | ||
| 308 | TSpChannelArray *GetChannels() const | ||
| 309 | { | ||
| 310 | return m_ppChannels; | ||
| 311 | } | ||
| 312 | |||
| 313 | /*! Gets the TeamSpeak server. | ||
| 314 | * \return TeamSpeak server. | ||
| 315 | * \sa TSServer | ||
| 316 | */ | ||
| 317 | TSServer *GetServer() const | ||
| 318 | { | ||
| 319 | return m_pServer; | ||
| 320 | } | ||
| 321 | |||
| 322 | /*! Gets the TeamSpeak connection. | ||
| 323 | * \return TeamSpeak connection. | ||
| 324 | * \sa TSConnection | ||
| 325 | */ | ||
| 326 | TSConnectionThread *GetConnection() const | ||
| 327 | { | ||
| 328 | return m_pConnection; | ||
| 329 | } | ||
| 330 | |||
| 331 | /*! Gets the session id. | ||
| 332 | * \return Session id. | ||
| 333 | */ | ||
| 334 | wxUint32 GetSessionId() const | ||
| 335 | { | ||
| 336 | return m_SessionId; | ||
| 337 | } | ||
| 338 | |||
| 339 | /*! Gets Sync object, for thread sync | ||
| 340 | * \return Sync object. | ||
| 341 | */ | ||
| 342 | TSCmd *GetSync() const | ||
| 343 | { | ||
| 344 | return m_pSync; | ||
| 345 | } | ||
| 346 | |||
| 347 | /*! Send a command to a Teasmpeak server. | ||
| 348 | * \param cmd Command to send. | ||
| 349 | * \return Returns false if fails, check GetLastError for details. | ||
| 350 | * \sa GetLastError() TSCommand for commands | ||
| 351 | */ | ||
| 352 | bool SendCommand(wxUint32 cmd); | ||
| 353 | |||
| 354 | /*! Send a command to a Teasmpeak server. | ||
| 355 | * \param cmd Command to send. | ||
| 356 | * \return Returns false if fails, check GetLastError for details. | ||
| 357 | * \sa GetLastError() TSCommand for commands | ||
| 358 | */ | ||
| 359 | bool SendCommand(TSCmd *cmd); | ||
| 360 | |||
| 361 | /*! Finds a player | ||
| 362 | * \param id Player id. | ||
| 363 | * \return Returns NULL if fails, check GetLastError for details. | ||
| 364 | * \sa GetLastError() | ||
| 365 | */ | ||
| 366 | TSPlayer *FindPlayer(wxUint32 id); | ||
| 367 | |||
| 368 | /*! Finds a player | ||
| 369 | * \param str Player nick. | ||
| 370 | * \return Returns NULL if fails, check GetLastError for details. | ||
| 371 | * \sa GetLastError() | ||
| 372 | */ | ||
| 373 | TSPlayer *FindPlayer(wxString const &str); | ||
| 374 | |||
| 375 | /*! Finds a channel | ||
| 376 | * \param id Channel id. | ||
| 377 | * \return Returns NULL if fails, check GetLastError for details. | ||
| 378 | * \sa GetLastError() | ||
| 379 | */ | ||
| 380 | TSChannel *FindChannel(wxUint32 id); | ||
| 381 | |||
| 382 | /*! Finds a channel | ||
| 383 | * \param id Channel id. | ||
| 384 | * \return Returns NULL if fails, check GetLastError for details. | ||
| 385 | * \sa GetLastError() | ||
| 386 | */ | ||
| 387 | TSChannel *FindChannel(wxString const &str); | ||
| 388 | |||
| 389 | /*! Finds default channel | ||
| 390 | * \return Returns NULL if fails, check GetLastError for details. | ||
| 391 | * \sa GetLastError() | ||
| 392 | */ | ||
| 393 | TSChannel *FindDefaultChannel(); | ||
| 394 | |||
| 395 | /*! Finds all channel with this parent id. | ||
| 396 | * \param id Channel id. | ||
| 397 | * \param channels Channel array | ||
| 398 | * \sa TSpChannelArray | ||
| 399 | */ | ||
| 400 | bool FindChannelsByParent(wxUint32 id, TSpChannelArray *channels); | ||
| 401 | |||
| 402 | /*! Finds all channels per name, regex. | ||
| 403 | * \param str Channel name. | ||
| 404 | * \param channels Channel array | ||
| 405 | * \sa TSpChannelArray | ||
| 406 | */ | ||
| 407 | bool FindChannelsByName(wxString const &str, TSpChannelArray *channels); | ||
| 408 | |||
| 409 | /*! Finds all players per name, regex. | ||
| 410 | * \param str Player name. | ||
| 411 | * \param players Player array | ||
| 412 | * \sa TSpPlayerArray | ||
| 413 | */ | ||
| 414 | bool FindPlayersByName(wxString const &str, TSpPlayerArray *players); | ||
| 415 | |||
| 416 | /*! Finds all players in channel. | ||
| 417 | * \param channel Channel. | ||
| 418 | * \param players Player array | ||
| 419 | * \sa TSpPlayerArray | ||
| 420 | */ | ||
| 421 | bool FindPlayersByChannel(TSChannel *channel, TSpPlayerArray *players); | ||
| 422 | |||
| 423 | /*! Creates a channel. | ||
| 424 | * \param channel Channel object. | ||
| 425 | * \return Returns false if fails, check GetLastError for details. | ||
| 426 | * \sa GetLastError() TSChannel | ||
| 427 | */ | ||
| 428 | bool CreateChannel(TSChannel *channel); | ||
| 429 | |||
| 430 | /*! Deletes a channel. | ||
| 431 | * \param channel Channel object. | ||
| 432 | * \return Returns false if fails, check GetLastError for details. | ||
| 433 | * \sa GetLastError() TSChannel | ||
| 434 | */ | ||
| 435 | bool DeleteChannel(TSChannel *channel); | ||
| 436 | |||
| 437 | /*! Modify a channel. | ||
| 438 | * \param channel Channel object. | ||
| 439 | * \return Returns false if fails, check GetLastError for details. | ||
| 440 | * \sa GetLastError() TSChannel | ||
| 441 | */ | ||
| 442 | bool ModifyChannel(TSChannel *channel); | ||
| 443 | |||
| 444 | /*! Moves a Player. | ||
| 445 | * \param player Player object. | ||
| 446 | * \return Returns false if fails, check GetLastError for details. | ||
| 447 | * \sa GetLastError() TSChannel | ||
| 448 | */ | ||
| 449 | bool MovePlayer(TSPlayer *player); | ||
| 450 | |||
| 451 | /*! Kick a Player. | ||
| 452 | * \param player Player object. | ||
| 453 | * \param msg Kick message. | ||
| 454 | * \return Returns false if fails, check GetLastError for details. | ||
| 455 | * \sa GetLastError() TSChannel | ||
| 456 | */ | ||
| 457 | bool KickPlayer(TSPlayer *player, wxString msg = _T("")); | ||
| 458 | |||
| 459 | /*! Dumps object. | ||
| 460 | * \param ostrm Stream to write. | ||
| 461 | */ | ||
| 462 | void Dump(wxOutputStream &ostrm) const; | ||
| 463 | |||
| 464 | private: | ||
| 465 | //Sets the LastError message. | ||
| 466 | void SetLastError(wxString const &str) | ||
| 467 | { | ||
| 468 | m_LastError = str; | ||
| 469 | } | ||
| 470 | |||
| 471 | //Members | ||
| 472 | TSPlayer *m_pPlayer; | ||
| 473 | TSpPlayerArray *m_ppPlayers; | ||
| 474 | TSChannel *m_pChannel; | ||
| 475 | TSpChannelArray *m_ppChannels; | ||
| 476 | TSServer *m_pServer; | ||
| 477 | TSConnectionThread *m_pConnection; | ||
| 478 | wxString m_LastError; | ||
| 479 | wxString m_VersionNumber; | ||
| 480 | wxString m_Platform; | ||
| 481 | wxUint32 m_SessionId; | ||
| 482 | wxMutex *m_pMutex; | ||
| 483 | TSCmd *m_pSync; | ||
| 484 | bool m_pReconnectAct; | ||
| 485 | public: | ||
| 486 | bool m_Lock; | ||
| 487 | }; | ||
| 488 | |||
| 489 | #endif | ||
