public void Login() { TS2Packet packet = new TS2Packet(); packet.Create(TS2.CONNECTION, TS2.LOGIN, 0x00000000, 0x00000000, SequenceNumber++); packet.Login(txtNickname.Text, txtUsername.Text, (string.IsNullOrEmpty(txtPassword.Text) ? txtServerPassword.Text : txtPassword.Text), txtPlatform.Text, txtOS.Text); net.Send(packet.toByteArray(), Target); }
public void Register() { TS2Packet packet = new TS2Packet(); packet.Create(TS2.STANDARD, TS2.REGISTER, this.SessionKey, this.ClientID, this.SequenceNumber); packet.Register(txtUsername.Text, txtPassword.Text); net.Send(packet.toByteArray(), Target); }
public void AckHandler( uint SequenceNumber ) { TS2Packet packet = new TS2Packet(); packet.Create(TS2.ACK, 0x0000, SessionKey, RealClientID, SequenceNumber); packet.Raw(new byte[] { 0x00 }); net.Send(packet.toByteArray(), Target); }
public void Ban(uint cid, string message) { /* f0be4501577a75005b0000000200000000000000f8bd354f54000000000011596572206120747572642c20647564652e060000000d000000b870b602 */ /* */ TS2Packet packet = new TS2Packet(); packet.Create(TS2.STANDARD, TS2.BANPLAYER, this.SessionKey, this.ClientID, this.SequenceNumber); packet.Raw(packet.combine(BitConverter.GetBytes(cid), new byte[] { 0x00, 0x00, (byte)message.Length }, packet.Pad(message, 29))); net.Send(packet.toByteArray(), Target); }
public void Disconnect() { TS2Packet packet = new TS2Packet(); packet.Create(TS2.STANDARD, TS2.DISCONNECT, this.SessionKey, this.ClientID, this.SequenceNumber); packet.Raw(new byte[] { }); net.Send(packet.toByteArray(), Target); disconnectPending = true; dcSequenceNumber = this.SequenceNumber; }
public void ServerAdmin(uint cid, bool give) { /* f0be3301a54c3d003f00000002000000000000005f718a7e0e0000000000 */ /* f0be3301ce8f36003f000000020000000000000006ef023b0e0000000000 */ /* f0be3301ffe32500450000000200000000000000630e5b4c0e0000000200 */ TS2Packet packet = new TS2Packet(); ushort action = give ? (ushort)0x0000 : (ushort)0x0002; packet.Create(TS2.STANDARD, TS2.GIVESA, this.SessionKey, this.ClientID, this.SequenceNumber); packet.Raw(packet.combine(BitConverter.GetBytes(cid), BitConverter.GetBytes(action))); net.Send(packet.toByteArray(), Target); }
public void Ping(uint SequenceNumber) { TS2Packet packet = new TS2Packet(); packet.Create(TS2.CONNECTION, TS2.PING, RealSessionKey, RealClientID, PingSequenceNumber++); packet.Raw(new byte[] {}); try { net.Send(packet.toByteArray(), Target); } catch (ObjectDisposedException ex) { net.Dispose(); Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); init(); } }
public void JoinServer() { TS2Packet packet = new TS2Packet(); packet.Create(TS2.STANDARD, TS2.LOGIN2, SessionKey, ClientID, SequenceNumber); packet.Raw( new byte[] { 0x01, 0x00, 0x00, 0x00, 0xf4, 0x3b, 0x46, 0x75, 0x3b, 0x6d, 0x92, 0x8a, 0x7c, 0xf8, 0x18, 0x00, 0xb4, 0xc4, 0x48, 0x00, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x5e, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7c, 0xf8, 0x18, 0x00, 0xb4, 0xc4, 0x48, 0x00, 0x7c, 0xf8, 0x18, 0x00, 0xb4, 0xc4, 0x48, 0x00, 0xfc, 0x9a, 0xb6, 0x02, 0xa6, 0x9f, 0x92, 0xd6, 0x00, 0x00, 0x00, 0x00 } ); net.Send(packet.toByteArray(), Target); Console.WriteLine("Sent LOGIN2"); }
public void SendMessage(uint target, string message, int opt) { TS2Packet packet = new TS2Packet(); packet.Create(TS2.STANDARD, TS2.MSGPLAYER, this.SessionKey, this.ClientID, this.SequenceNumber); switch (opt) { case 2: /* player */ packet.Raw(packet.combine(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x02 }, BitConverter.GetBytes(target), packet.Pad(message, message.Length + 1))); break; case 1: /* channel */ packet.Raw(packet.combine(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x01 }, BitConverter.GetBytes(target), packet.Pad(message, message.Length + 1))); break; case 0: /* server */ packet.Raw(packet.combine(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, packet.Pad(message, message.Length + 1))); break; } net.Send(packet.toByteArray(), Target); }
private void net_Received(object sender, UdpPacketReceivedEventArgs e) { TS2Packet packet = new TS2Packet(); packet.ReadPacket(e.Response.Buffer); ClientID = packet.ClientID; RealClientID = packet.ClientID; Stream stream = null; BinaryReader reader = null; try { if (packet.Data == null) { packet.Data = new byte[] { 0x00 }; } stream = new MemoryStream(packet.Data); reader = new BinaryReader(stream); } catch (Exception err) { } switch (packet.Class) { case TS2.CONNECTION: switch (packet.Type) { case TS2.LOGINREPLY: LoginHandler(reader); break; case TS2.PING_REPLY: PingSequenceNumber = packet.SequenceNumber+1; break; default: Console.WriteLine("Unhandled Packet Type"); break; } break; case TS2.STANDARD: switch (packet.Type) { case TS2.PLAYERLIST: PlayerListHandler(reader); break; case TS2.CHANNELLIST: if (pingThread == null) { pingThread = new Thread(new ThreadStart(PingThread)); pingThread.Start(); } break; case TS2.NEWPLAYER: NewPlayerHandler(reader); break; case TS2.PLAYERQUIT: Console.WriteLine("Player left!"); PlayerQuitHandler(reader); break; default: break; } AckHandler(packet.SequenceNumber); break; case TS2.ACK: if (disconnectPending) { if (packet.SequenceNumber == this.dcSequenceNumber) { disconnectPending = false; } } AckHandler(packet.SequenceNumber); this.SequenceNumber = packet.SequenceNumber + 1; break; default: Console.WriteLine("Unknown Packet"); break; } }