From 310a2c101b32a5e71a616027b6a1b788a341bc02 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 5 Mar 2013 17:39:48 +0100 Subject: initial GPLv2 release --- tscommand.cpp | 1519 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1519 insertions(+) create mode 100644 tscommand.cpp (limited to 'tscommand.cpp') diff --git a/tscommand.cpp b/tscommand.cpp new file mode 100644 index 0000000..881ce70 --- /dev/null +++ b/tscommand.cpp @@ -0,0 +1,1519 @@ +/* + * 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; version 2 of the License. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Manuel Mausz (manuel@mausz.at) + * Christian Raschko (c.raschko@netcore.at) + */ + +// Header +#include "tscommand.h" +#include "wxstreamex.h" +#include "wxbufferex.h" +#include "crc32.h" + +//Libraries +#include +#include +#include +#include + +IMPLEMENT_CLASS(TSCommand, wxObject) + +//class variable +wxUint32 TSCommand::m_Cnt = 0; + +//------------------------------------------------------------------------------ +// Send User +bool TSCmdSendLogin::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + TSCommand::m_Cnt = 0; + + out.Write32(m_Id); + out.Write32(0); //SessionId + out.Write32(0); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //CRC + out.WriteFixedString(_T("TeamSpeak")); //TeamSpeak + out.WriteFixedString(client->GetPlatform()); //Platform + + //Write version number + wxStringTokenizer tkz(client->GetVersionNumber(), _T(".")); + if(tkz.CountTokens() != 4) + { + SetLastError(_T("invalid version number, check format")); + return false; + } + + //some conversions + long i; + tkz.GetNextToken().ToLong(&i); + out.Write16(wxUint16(i)); + tkz.GetNextToken().ToLong(&i); + out.Write16(wxUint16(i)); + tkz.GetNextToken().ToLong(&i); + out.Write16(wxUint16(i)); + tkz.GetNextToken().ToLong(&i); + out.Write16(wxUint16(i)); + + out.Write8(client->GetPlayer()->GetServerAssingnsNickname()); //Allow server assing nick + + out.Write8(client->GetPlayer()->GetAnonymous()); //Anonymous login + out.WriteFixedString(client->GetPlayer()->GetLoginName()); //Login name + out.WriteFixedString(client->GetPlayer()->GetLoginPassword()); //Login password + out.WriteFixedString(client->GetPlayer()->GetNickname()); //Nickname + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(16); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// Recv Server +bool TSCmdRecvServer::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxString str; + wxUint32 crc = 0; + wxUint32 id; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + client->GetPlayer()->SetId(in.Read32()); //Player id + in.Read32(); //Packet count + crc = in.Read32(); //CRC + in.ReadFixedString(str); + client->GetServer()->SetServerMessage(str); //Server message + str.Clear(); + in.ReadFixedString(str); + client->GetServer()->SetPlatform(str); //Platform string + str.Clear(); + str.Append(wxString::Format(_T("%d."), in.Read16())); + str.Append(wxString::Format(_T("%d."), in.Read16())); + str.Append(wxString::Format(_T("%d."), in.Read16())); + str.Append(wxString::Format(_T("%d"), in.Read16())); + client->GetServer()->SetVersionNumber(str); + id = in.Read32(); + if(id == 0xffffffff) + { + SetLastError(_T("Bad Login (name and/or password wrong)")); + return false; + } + if(id == 0xfffffff9) + { + SetLastError(_T("This user is already logged in on the server")); + return false; + } + if(id > 100) + { + SetLastError(_T("Undefined user login error, check user data/permission")); + return false; + } + client->GetServer()->SetId(id); + + in.Read32(); //unknown + in.Read32(); //unknown + client->GetServer()->SetServerType(in.Read16()); // servertype + + //more unknown data + for(int i = 0; i < 70; i++) + in.Read8(); + + client->SetSessionId(in.Read32()); //Session id + client->GetPlayer()->SetId(in.Read32()); //Player id + str.Clear(); + in.ReadFixedString(str, 255); + client->GetServer()->SetWelcomeMessage(str); //Welcome message + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// Send default channel +bool TSCmdSendDefault::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //CRC + out.Write16(1); + out.WriteFixedString(client->GetPlayer()->GetDefaultChannel()); + out.WriteFixedString(client->GetPlayer()->GetDefaultSubchannel()); + out.WriteFixedString(client->GetPlayer()->GetDefaultChannelPassword()); + out.Write32(0); //unknown + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSRecvChannel +bool TSCmdRecvChannel::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxString str; + wxUint32 crc = 0; + wxUint32 channels = 0; + TSChannel *chl = NULL; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + channels = in.Read32(); //read channel count + + for(size_t i = 0; i < channels; i++) + { + wxUint32 chlid = in.Read32(); + chl = client->FindChannel(chlid); + if(chl == NULL) + { + chl = new TSChannel; + client->GetChannels()->Add(chl); + } + + chl->SetId(chlid); + chl->SetFlags(in.Read16()); + chl->SetCodec(in.Read16()); + chl->SetParent(in.Read32()); + chl->SetOrder(in.Read16()); + chl->SetMaxUsers(in.Read16()); + str.Clear(); + in.ReadZeroString(str); + chl->SetName(str); + str.Clear(); + in.ReadZeroString(str); + chl->SetTopic(str); + str.Clear(); + in.ReadZeroString(str); + chl->SetDescription(str); + } + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSRecvUser +bool TSCmdRecvUser::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxString str; + wxUint32 crc = 0; + wxUint32 players = 0; + TSPlayer *ply = NULL; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + players = in.Read32(); + + for(size_t i = 0; i < players; i++) + { + wxUint32 plyid = in.Read32(); + ply = client->FindPlayer(plyid); + if(ply == NULL) + { + ply = new TSPlayer; + client->GetPlayers()->Add(ply); + } + + ply->SetId(plyid); + ply->SetChannelId(in.Read32()); + ply->SetChannelPrivileges(in.Read16()); + ply->SetPrivileges(in.Read16()); + ply->SetFlags(in.Read16()); + str.Clear(); + in.ReadFixedString(str); + ply->SetNickname(str); + } + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSRecvAck +bool TSCmdRecvAck::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + wxUint32 crc = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + crc = in.Read32(); //CRC + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + + +//------------------------------------------------------------------------------ +// TSSendAck + +bool TSCmdSendAck::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(TS_CMD_RECV_ACK); //same id as recv + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(cmd->pktid); //Counter + len = tmpstrm.CopyTo(buf, 1024); + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSRecvUrl +bool TSCmdRecvUrl::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + wxUint32 crc = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + crc = in.Read32(); //CRC + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSSendPing +bool TSCmdSendPing::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + static wxUint32 cnt = 2; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(cnt++); //Counter + out.Write32(0); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(16); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSRecvPing +bool TSCmdRecvPing::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + //only for reducing warnings + wxUnusedVar(istrm); + wxUnusedVar(ostrm); + wxUnusedVar(cmd); + return true; +} + +//------------------------------------------------------------------------------ +// SendLogout +bool TSCmdSendLogout::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); + out.Write32(0); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// RecvLogoutInfo +bool TSCmdRecvLogout::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxUint32 crc = 0; + wxUint32 id; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); + crc = in.Read32(); //CRC + id = in.Read32(); + + for(size_t i = 0; i < client->GetPlayers()->GetCount(); i++) + { + if(id == client->GetPlayers()->Item(i)->GetId()) + { + delete client->GetPlayers()->Item(i); + client->GetPlayers()->RemoveAt(i); + return true; + } + } + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + + SetLastError(_T("unknown player, not found in list, can't remove")); + return false; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvAddPlayer +bool TSCmdRecvAddPlayer::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxString str; + wxUint32 crc = 0; + wxUint32 id = 0; + TSPlayer *ply = NULL; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + id = in.Read32(); //Player id + ply = client->FindPlayer(id); + + if(ply == NULL) + { + ply = new TSPlayer; + client->GetPlayers()->Add(ply); + } + + ply->SetId(id); + ply->SetChannelId(in.Read32()); + ply->SetChannelPrivileges(in.Read16()); + ply->SetPrivileges(in.Read16()); + ply->SetFlags(in.Read16()); + str.Clear(); + in.ReadFixedString(str); + ply->SetNickname(str); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvPlayerFlags +bool TSCmdRecvPlayerFlags::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSPlayer *ply = NULL; + wxUint32 crc = 0; + wxUint32 plyid = 0; + wxUint32 plyflags = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + plyid = in.Read32(); + plyflags = in.Read16(); + + ply = client->FindPlayer(plyid); + if(ply != NULL) + { + ply->SetFlags(plyflags); + return true; + } + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + + SetLastError(_T("unknown player, not found in list, flags not set")); + return false; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvAddChannel +bool TSCmdRecvAddChannel::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSChannel *chl = NULL; + wxString str; + wxUint32 crc = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + in.Read32(); //user + chlid = in.Read32(); + chl = client->FindChannel(chlid); + if(chl == NULL) + { + chl = new TSChannel; + client->GetChannels()->Add(chl); + } + + chl->SetId(chlid); + chl->SetFlags(in.Read16()); + chl->SetCodec(in.Read16()); + chl->SetParent(in.Read32()); + chl->SetOrder(in.Read16()); + chl->SetMaxUsers(in.Read16()); + str.Clear(); + in.ReadZeroString(str); + chl->SetName(str); + str.Clear(); + in.ReadZeroString(str); + chl->SetTopic(str); + str.Clear(); + in.ReadZeroString(str); + chl->SetDescription(str); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvMovePlayer +bool TSCmdRecvMovePlayer::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSPlayer *ply = NULL; + wxUint32 crc = 0; + wxUint32 plyid = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + plyid = in.Read32(); + in.Read32(); //old channel + chlid = in.Read32(); //new channel + in.Read16(); //unknown + + ply = client->FindPlayer(plyid); + if(ply != NULL) + { + ply->SetChannelId(chlid); + return true; + } + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + + SetLastError(_T("unknown player, not found in list, channel not set")); + return false; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvMovePlayer +bool TSCmdRecvMovePlayer2::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSPlayer *ply = NULL; + wxUint32 crc = 0; + wxUint32 plyid = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + plyid = in.Read32(); + in.Read32(); //old channel + chlid = in.Read32(); //new channel + in.Read16(); //unknown + + ply = client->FindPlayer(plyid); + if(ply != NULL) + { + ply->SetChannelId(chlid); + return true; + } + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + + SetLastError(_T("unknown player, not found in list, channel not set")); + return false; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvDelChannel +bool TSCmdRecvDelChannel::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxUint32 crc = 0; + wxUint32 plyid = 0; + wxUint16 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + chlid = in.Read16(); // channel + plyid = in.Read32(); + + for(size_t i = 0; i < client->GetChannels()->GetCount(); i++) + { + if(chlid == client->GetChannels()->Item(i)->GetId()) + { + delete client->GetChannels()->Item(i); + client->GetChannels()->RemoveAt(i); + return true; + } + } + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + wxUnusedVar(plyid); + + SetLastError(_T("unknown channel, not found in list")); + return false; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvServerUpdate +bool TSCmdRecvServerUpdate::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + wxUint32 crc = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + + // in.Read32(); //unknown + // in.Read32(); //unknown + // servertype = in.Read16(); //clan=05, public=06 + // more unknown data + // all over 80 byte (so 62 left or so) + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendAddChannel +bool TSCmdSendAddChannel::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(0); //must be null + + out.Write16(cmd->param1.pChannel->GetFlags()); + out.Write16(cmd->param1.pChannel->GetCodec()); + out.Write32(cmd->param1.pChannel->GetParent()); + out.Write16(cmd->param1.pChannel->GetOrder()); + out.Write16(cmd->param1.pChannel->GetMaxUsers()); + out.WriteZeroString(cmd->param1.pChannel->GetName()); + out.WriteZeroString(cmd->param1.pChannel->GetTopic()); + out.WriteZeroString(cmd->param1.pChannel->GetDescription()); + if (cmd->param1.pChannel->GetPassword().Length() > 0) + out.WriteZeroString(cmd->param1.pChannel->GetPassword()); + else + out.Write8(0); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendDelChannel +bool TSCmdSendDelChannel::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendMovePlayer +bool TSCmdSendMovePlayer::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pPlayer->GetId()); + out.Write32(cmd->param1.pPlayer->GetChannelId()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendSetChannelPassword +bool TSCmdSendSetChannelPassword::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + out.WriteFixedString(cmd->param1.pChannel->GetPassword()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendSetChannelName +bool TSCmdSendSetChannelName::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + out.WriteZeroString(cmd->param1.pChannel->GetName()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + wxUnusedVar(ostrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendSetChannelTopic +bool TSCmdSendSetChannelTopic::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + out.WriteZeroString(cmd->param1.pChannel->GetTopic()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendSetChannelDescription +bool TSCmdSendSetChannelDescription::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + out.WriteZeroString(cmd->param1.pChannel->GetDescription()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendSetChannelMaxPlayers +bool TSCmdSendSetChannelMaxPlayers::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + out.Write16(cmd->param1.pChannel->GetMaxUsers()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + wxUnusedVar(ostrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendSetChannelFlagsCodec +bool TSCmdSendSetChannelFlagsCodec::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + out.Write16(cmd->param1.pChannel->GetFlags()); + out.Write16(cmd->param1.pChannel->GetCodec()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendSetChannelOrder +bool TSCmdSendSetChannelOrder::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pChannel->GetId()); + out.Write16(cmd->param1.pChannel->GetOrder()); + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvSetChannelName +bool TSCmdRecvSetChannelName::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSChannel *chl = NULL; + wxString str; + wxUint32 crc = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + chlid = in.Read32(); + + chl = client->FindChannel(chlid); + if(chl == NULL) + { + SetLastError(_T("can't find channel")); + return false; + } + + in.Read32(); //user id + + str.Clear(); + in.ReadZeroString(str); + chl->SetName(str); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvSetChannelTopic +bool TSCmdRecvSetChannelTopic::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSChannel *chl = NULL; + wxString str; + wxUint32 crc = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + chlid = in.Read32(); + + chl = client->FindChannel(chlid); + if(chl == NULL) + { + SetLastError(_T("can't find channel")); + return false; + } + + in.Read32(); //user id + + str.Clear(); + in.ReadZeroString(str); + chl->SetTopic(str); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvSetChannelDescription +bool TSCmdRecvSetChannelDescription::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSChannel *chl = NULL; + wxString str; + wxUint32 crc = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + chlid = in.Read32(); + + chl = client->FindChannel(chlid); + if(chl == NULL) + { + SetLastError(_T("can't find channel")); + return false; + } + + in.Read32(); //user id + + str.Clear(); + in.ReadZeroString(str); + chl->SetDescription(str); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvSetChannelMaxPlayers +bool TSCmdRecvSetChannelMaxPlayers::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSChannel *chl = NULL; + wxUint32 crc = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + chlid = in.Read32(); + + chl = client->FindChannel(chlid); + if(chl == NULL) + { + SetLastError(_T("can't find channel")); + return false; + } + + chl->SetMaxUsers(in.Read16()); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvSetChannelFlagsCodec +bool TSCmdRecvSetChannelFlagsCodec::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSChannel *chl = NULL; + wxUint32 crc = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + chlid = in.Read32(); + + chl = client->FindChannel(chlid); + if(chl == NULL) + { + SetLastError(_T("can't find channel")); + return false; + } + + chl->SetFlags(in.Read16()); + chl->SetCodec(in.Read16()); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvSetChannelOrder +bool TSCmdRecvSetChannelOrder::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + TSChannel *chl = NULL; + wxUint32 crc = 0; + wxUint32 chlid = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + chlid = in.Read32(); + + chl = client->FindChannel(chlid); + if(chl == NULL) + { + SetLastError(_T("can't find channel")); + return false; + } + + chl->SetOrder(in.Read32()); + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdSendKickPlayer +bool TSCmdSendKickPlayer::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + TSClient *client = cmd->client; + wxByte buf[1024]; + wxUint32 len = 0; + wxMemoryOutputStream tmpstrm; + wxDataOutputStreamEx out(tmpstrm); + + out.Write32(m_Id); + out.Write32(client->GetSessionId()); //SessionId + out.Write32(client->GetPlayer()->GetId()); //PlayerId + out.Write32(m_Cnt++); //Counter + out.Write32(0); //unknown + out.Write32(0); //crc + + out.Write32(cmd->param1.pPlayer->GetId()); + out.WriteFixedString(*cmd->param2.pString); + + + len = tmpstrm.CopyTo(buf, 1024); + CRC32 myCRC32; + myCRC32.update(buf, len); + + tmpstrm.SeekO(20); + out.Write32(myCRC32.getUint32Value()); + len = tmpstrm.CopyTo(buf, len); + + ostrm.Write(buf, len); + + //only for reducing warnings + wxUnusedVar(istrm); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvChannelPasswordChanged +bool TSCmdRecvChannelPasswordChanged::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + wxUint32 crc = 0; + wxDataInputStreamEx in(istrm); + + //read id + if(in.Read32() != m_Id) + { + SetLastError(_T("invalid command")); + return false; + } + + in.Read32(); //Session id + in.Read32(); //Player id + cmd->pktid = in.Read32(); //Packet count + in.Read32(); //read unknown + crc = in.Read32(); //CRC + + //do nothing + + //only for reducing warnings + wxUnusedVar(ostrm); + wxUnusedVar(crc); + return true; +} + +//------------------------------------------------------------------------------ +// TSCmdRecvUnknown +bool TSCmdRecvUnknown::ProcessCommand(wxInputStream &istrm, wxOutputStream &ostrm, TSCmd *cmd) +{ + wxMemoryBufferEx buf(1024); + wxUint32 cnt = 0; + + while(!istrm.Eof()) + { + cnt++; + buf.AppendByte(istrm.GetC()); + } + buf.SetDataLen(cnt); + wxMemoryInputStream tmp(buf.GetData(), buf.GetDataLen()); + wxDataInputStreamEx in(tmp); + + wxLogVerbose(_T("dumping unknown command...")); + + wxLogVerbose(_T("Id: %#x"), in.Read32()); //read id + wxLogVerbose(_T("SessionId: %#x"), in.Read32()); //Session id + wxLogVerbose(_T("PlayerId: %#x"), in.Read32()); //Player id + + cmd->pktid = in.Read32(); //Packet count + wxLogVerbose(_T("PacketId: %#x"), cmd->pktid); + + wxStringOutputStream so; + buf.HexDump(so); + wxLogVerbose(_T("Hex dump:\n%s"), so.GetString().c_str()); + + //only for reducing warnings + wxUnusedVar(ostrm); + return true; +} + -- cgit v1.2.3