public ANS_DISTRICT_ENTER(District district, WorldClient client) : base((UInt32)Opcodes.ANS_DISTRICT_ENTER) { if (district != null) { WriteInt32((int)ResponseCodes.RC_SUCCESS); string[] delimiter = new string[] { "." }; string[] result = district.IP.Split(delimiter, StringSplitOptions.None); foreach (string s in result) WriteByte(Convert.ToByte(s)); WriteUInt16Reverse(2108); WriteInt32Reverse(TcpServer.GetTimeStamp()); } else WriteUInt32Reverse((uint)ResponseCodes.RC_DISTRICT_RESERVE_DISTRICT_OFFLINE); }
private void handleWorld(object client) { TcpClient tcpClient = (TcpClient)client; NetworkStream clientStream = tcpClient.GetStream(); District district = new District(0, 0); district.tcp = tcpClient; Byte[] message = new Byte[4096]; Int32 bytesRead; while (true) { bytesRead = 0; try { bytesRead = clientStream.Read(message, 0, message.Length); } catch { break; } if (bytesRead == 0) { break; } IPacket packet = null; switch (message[0]) { case (Byte)OpCodes.DW_REGISTER_DISTRICT: packet = new RegisterDistrict(); break; } packet.Write(message, 1, bytesRead - 1); packet.Handle(district); } tcpClient.Close(); }
private void handleWorld(object client) { TcpClient tcpClient = (TcpClient)client; District district = new District(tcpClient); NetworkStream clientStream = tcpClient.GetStream(); Byte[] message = new Byte[4096]; Int32 bytesRead; while (true) { bytesRead = 0; try { bytesRead = clientStream.Read(message, 0, message.Length); } catch { break; } if (bytesRead == 0) { break; } IPacket packet = null; switch (message[0]) { case (Byte)OpCodes.DW_REGISTER_DISTRICT: packet = new RegisterDistrict(); break; } packet.Write(message, 1, bytesRead - 1); packet.Handle(district); } try { lock (DistrictsTcp) { foreach (KeyValuePair<TcpClient, UInt32> dtcp in DistrictsTcp) { lock (Districts) { foreach (KeyValuePair<UInt32, District> dis in Districts) { if (dis.Key == dtcp.Value) { Log.Error("Listener", dis.Value.ToString() + " disconnected!"); break; } } Districts.Remove(dtcp.Value); break; } } DistrictsTcp.Remove(tcpClient); } tcpClient.Close(); } catch (Exception e) { Log.Error("Districts.Listener", "Following exception was thrown when trying to remove district server:\n\n"); Console.WriteLine(e.ToString()); return; } }