private void AuthRequestPacketHandler(ListenerPacket pck, NetworkStream stream, string hst, int bck) { // opcode is already read, DO _NOT_ READ AGAIN string guid = pck.Read <string>(); string hash = pck.Read <string>(); if (hash != sUtilities.Md5(ListenerConfig.Password)) { Log.Warning("AuthHandler", sLConsole.GetString("Auth unsuccessful! Guid of client: {0}"), guid); Log.Debug("Security", sLConsole.GetString("Hash was: {0}"), hash); Log.Notice("AuthHandler", sLConsole.GetString("Back port is: {0}"), bck); var packet = new ListenerPacket(); packet.Write <int>((int)ListenerOpcode.SMSG_AUTH_DENIED); packet.Write <int>((int)0); SendPacketBack(packet, stream, hst, bck); } else { if (!_HostList.ContainsKey(hst + SchumixBase.Colon + bck)) { _HostList.Add(hst + SchumixBase.Colon + bck, new Host(stream, guid, hst, bck)); } _HostList[hst + SchumixBase.Colon + bck].LastPing = DateTime.Now; Log.Success("AuthHandler", sLConsole.GetString("Auth successful. Guid of client: {0}"), guid); Log.Debug("Security", sLConsole.GetString("Hash was: {0}"), hash); Log.Notice("AuthHandler", sLConsole.GetString("Back port is: {0}"), bck); var packet = new ListenerPacket(); packet.Write <int>((int)ListenerOpcode.SMSG_AUTH_APPROVED); packet.Write <int>((int)1); SendPacketBack(packet, stream, hst, bck); } }
public void HandlePacket(ListenerPacket packet, TcpClient client, NetworkStream stream) { var hst = client.Client.RemoteEndPoint.ToString().Split(SchumixBase.Colon)[0]; int bck = client.Client.RemoteEndPoint.ToString().Split(SchumixBase.Colon)[1].ToInt32(); int packetid = 0; try { packetid = packet.Read <int>(); } catch (Exception) { var packet2 = new ListenerPacket(); packet2.Write <int>((int)ListenerOpcode.SCMSG_PACKET_NULL); packet2.Write <string>(sLConsole.GetString("Wrong packetid, aborting connection!")); SendPacketBack(packet2, stream, hst, bck); Log.Warning("SchumixPacketHandler", sLConsole.GetString("Wrong packetid, aborting connection!")); return; } Log.Debug("SchumixPacketHandler", sLConsole.GetString("Got packet with ID: {0} from: {1}"), packetid, client.Client.RemoteEndPoint); if (!_AuthList.ContainsKey(hst + SchumixBase.Colon + bck)) { if (packetid != (int)ListenerOpcode.CMSG_REQUEST_AUTH) { var packet2 = new ListenerPacket(); packet2.Write <int>((int)ListenerOpcode.SMSG_AUTH_DENIED); packet2.Write <int>((int)0); SendPacketBack(packet2, stream, hst, bck); return; } else { _AuthList.Add(hst + SchumixBase.Colon + bck, true); } } if (PacketMethodMap.ContainsKey((ListenerOpcode)packetid)) { PacketMethodMap[(ListenerOpcode)packetid].Method.Invoke(packet, stream, hst, bck); return; } else { Log.Notice("SchumixPacketHandler", sLConsole.GetString("Received unhandled packetid: {0}"), packetid); } }
private void CloseHandler(ListenerPacket pck, NetworkStream stream, string hst, int bck) { if (_HostList.ContainsKey(hst + SchumixBase.Colon + bck)) { _HostList.Remove(hst + SchumixBase.Colon + bck); } if (_AuthList.ContainsKey(hst + SchumixBase.Colon + bck)) { _AuthList.Remove(hst + SchumixBase.Colon + bck); } string guid = pck.Read <string>(); Log.Warning("CloseHandler", sLConsole.GetString("Connection closed! Guid of client: {0}"), guid); }