Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.IO;
- using System.Linq;
- using System.Threading;
- class TcpEchoServer
- {
- static void Main(string[] args)
- {
- Thread authServer = new Thread(startAuthServer);
- Thread gameServer = new Thread(startGameServer);
- authServer.Start();
- gameServer.Start();
- }
- public static void startGameServer()
- {
- try
- {
- // while (true)
- // {
- int recv;
- byte[] data;
- IPEndPoint ipep = new IPEndPoint(IPAddress.Any,
- 29890);
- Socket newsock = new
- Socket(AddressFamily.InterNetwork,
- SocketType.Stream, ProtocolType.Tcp);
- newsock.Bind(ipep);
- newsock.Listen(10);
- Console.WriteLine("[Game] Waiting for a client...");
- Socket client = newsock.Accept();
- IPEndPoint clientep =
- (IPEndPoint)client.RemoteEndPoint;
- Console.WriteLine("[Game] Connected with {0} at port {1}",
- clientep.Address, clientep.Port);
- client.Send(new byte[] { 0, 0, 0, 0 });
- //client.Send(new byte[] { 0x9f, 0x00, 0x02, 0x02, 0x00, 0x85, 0xa8, 0x07, 0x00, 0x00, 0x59, 0x28, 0x02, 0x0b, 0x00, 0x09, 0x00, 0x85, 0x00, 0x80, 0x00, 0x83, 0x69, 0xcc, 0x95, 0xfb, 0x66, 0xfa, 0xe4, 0xb8, 0x58, 0xfc, 0x4b, 0x31, 0xaf, 0xc2, 0xd6, 0xb6, 0x1c, 0x8c, 0x92, 0x39, 0x10, 0x53, 0x70, 0x14, 0xf2, 0x39, 0x18, 0x1f, 0x95, 0x49, 0xd0, 0x56, 0x3d, 0x03, 0x03, 0xfb, 0x4a, 0xea, 0x20, 0xc2, 0xed, 0xd1, 0x96, 0xef, 0xba, 0x96, 0xa7, 0x25, 0xc0, 0x65, 0xe7, 0x93, 0x3d, 0x0d, 0x82, 0xf8, 0x99, 0xea, 0x09, 0x30, 0xa8, 0xbc, 0x97, 0xe4, 0xe6, 0x58, 0xa7, 0x49, 0x28, 0xa5, 0xcd, 0x32, 0x62, 0x32, 0xad, 0xc0, 0xe5, 0x90, 0x27, 0xae, 0x2c, 0x7e, 0x55, 0xb9, 0xcf, 0x9b, 0xa3, 0x9a, 0x00, 0x3e, 0x37, 0x95, 0x2f, 0x2b, 0x34, 0x04, 0xf7, 0x93, 0xeb, 0x74, 0x86, 0xc7, 0xee, 0x22, 0x17, 0xb6, 0x9d, 0xbd, 0x0a, 0x1a, 0x2f, 0xed, 0x4d, 0xc4, 0x75, 0xdc, 0x0b, 0xf3, 0x88, 0x9a, 0x2d, 0xfb, 0xc8, 0x5c, 0xf4, 0xd1, 0x9e, 0x01, 0x00, 0x11, 0x0a, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04 }, SocketFlags.None);
- /*Stream s = new MemoryStream();
- byte[] d = new byte[]{
- 1, 0, 0, 0,
- 1, 0, 0, 127,
- 0xC2, 0x74,
- 1, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 0,
- 2,
- 0, 0, 0, 0,
- 1, 0, 0, 127,
- 0, 0,
- 5,
- 0, 0,
- 0, 0, 0, 0,
- 1, 0, 0, 0,
- 1, 0, 0, 127,
- 0xA1, 0x26,
- 1, 0, 0, 0,
- 0xFF, 0x00, 0x00, 0x00,
- 0x00, 0x00};
- byte[] packetsz = new byte[0];
- //packetsz.Concat(BitConverter.GetBytes((short)d.Length).Reverse()).Concat(BitConverter.GetBytes((short)0x801).Reverse()).Concat(d);
- packetsz = packetsz.Concat(BitConverter.GetBytes((short)0)).Concat(BitConverter.GetBytes((short)0x801)).ToArray();
- client.Send(packetsz, SocketFlags.None);*/
- while (true)
- {
- data = new byte[client.Available];
- recv = client.Receive(data);
- if (recv == 0)
- break;
- Console.WriteLine("[Game] Received:" + nicePacketString(data));
- Packet packet = new Packet(data);
- packet.Parse();
- //client.Send(data, recv, SocketFlags.None);
- }
- // Console.WriteLine("[Game] Disconnected from {0}",
- // clientep.Address);
- //client.Close();
- //newsock.Close();
- // }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.StackTrace);
- }
- }
- public static void startAuthServer()
- {
- try
- {
- //while (true)
- //{
- int recv;
- byte[] data;
- IPEndPoint ipep = new IPEndPoint(IPAddress.Any,
- 39190);
- Socket newsock = new
- Socket(AddressFamily.InterNetwork,
- SocketType.Stream, ProtocolType.Tcp);
- newsock.Bind(ipep);
- newsock.Listen(10);
- Console.WriteLine("[Auth] Waiting for a client...");
- Socket client = newsock.Accept();
- IPEndPoint clientep =
- (IPEndPoint)client.RemoteEndPoint;
- Console.WriteLine("[Auth] Connected with {0} at port {1}",
- clientep.Address, clientep.Port);
- client.Send(new byte[] { 0, 0, 0, 0 });
- client.Send(new byte[] { 0x9f, 0x00, 0x02, 0x02, 0x00, 0x85, 0xa8, 0x07, 0x00, 0x00, 0x59, 0x28, 0x02, 0x0b, 0x00, 0x09, 0x00, 0x85, 0x00, 0x80, 0x00, 0x83, 0x69, 0xcc, 0x95, 0xfb, 0x66, 0xfa, 0xe4, 0xb8, 0x58, 0xfc, 0x4b, 0x31, 0xaf, 0xc2, 0xd6, 0xb6, 0x1c, 0x8c, 0x92, 0x39, 0x10, 0x53, 0x70, 0x14, 0xf2, 0x39, 0x18, 0x1f, 0x95, 0x49, 0xd0, 0x56, 0x3d, 0x03, 0x03, 0xfb, 0x4a, 0xea, 0x20, 0xc2, 0xed, 0xd1, 0x96, 0xef, 0xba, 0x96, 0xa7, 0x25, 0xc0, 0x65, 0xe7, 0x93, 0x3d, 0x0d, 0x82, 0xf8, 0x99, 0xea, 0x09, 0x30, 0xa8, 0xbc, 0x97, 0xe4, 0xe6, 0x58, 0xa7, 0x49, 0x28, 0xa5, 0xcd, 0x32, 0x62, 0x32, 0xad, 0xc0, 0xe5, 0x90, 0x27, 0xae, 0x2c, 0x7e, 0x55, 0xb9, 0xcf, 0x9b, 0xa3, 0x9a, 0x00, 0x3e, 0x37, 0x95, 0x2f, 0x2b, 0x34, 0x04, 0xf7, 0x93, 0xeb, 0x74, 0x86, 0xc7, 0xee, 0x22, 0x17, 0xb6, 0x9d, 0xbd, 0x0a, 0x1a, 0x2f, 0xed, 0x4d, 0xc4, 0x75, 0xdc, 0x0b, 0xf3, 0x88, 0x9a, 0x2d, 0xfb, 0xc8, 0x5c, 0xf4, 0xd1, 0x9e, 0x01, 0x00, 0x11, 0x0a, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04 }, SocketFlags.None);
- client.Send(new byte[] { 0x0a, 0x00, 0x03, 0x01, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, SocketFlags.None); //Wrong password Packet
- byte[] d = new byte[]{
- 1, 0, 0, 0,
- 1, 0, 0, 127,
- 0x74, 0xC2,
- 1, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 0,
- 2,
- 0, 0, 0, 0,
- 1, 0, 0, 127,
- 0, 0,
- 5,
- 0, 0,
- 0, 0, 0, 0,
- 1, 0, 0, 0,
- 1, 0, 0, 127,
- 0x26, 0xA1,
- 1, 0, 0, 0,
- 0xFF, 0x00, 0x00, 0x00,
- 0x00, 0x00};
- byte[] packetsz = new byte[0];
- packetsz = packetsz.Concat(BitConverter.GetBytes((short)d.Length)).Concat(BitConverter.GetBytes((short)0x801)).Concat(d).ToArray();
- //packetsz = packetsz.Concat(BitConverter.GetBytes((short)0)).Concat(BitConverter.GetBytes((short)0x801)).ToArray();
- Console.WriteLine("Sending: " + nicePacketString(packetsz));
- client.Send(packetsz, SocketFlags.None);
- while (true)
- {
- data = new byte[1024];
- recv = client.Receive(data);
- if (recv == 0)
- break;
- //Console.WriteLine("[Auth] Received:" + nicePacketString(data));
- Packet packet = new Packet(data);
- packet.Parse();
- //client.Send(data, recv, SocketFlags.None);
- }
- //Console.WriteLine("[Auth] Disconnected from {0}",
- // clientep.Address);
- //client.Close();
- //newsock.Close();
- // }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.StackTrace);
- }
- }
- public static string nicePacketString(byte[] bytes)
- {
- return BitConverter.ToString(bytes).Replace("-", " ");
- }
- public static void writePacketToFile(byte[] data)
- {
- string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- StringBuilder sb = new StringBuilder();
- sb.AppendLine();
- foreach(byte b in data)
- {
- sb.Append((char)b);
- }
- sb.AppendLine();
- using (StreamWriter outfile = new StreamWriter(mydocpath + @"\UserInputFile.txt", true))
- {
- outfile.Write(sb.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement