コード例 #1
0
        private void AuthRequestPacketHandler(SchumixPacket 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(ServerConfigs.Password))
            {
                if (_HostList.ContainsKey(hst + SchumixBase.Colon + bck))
                {
                    _HostList.Remove(hst + SchumixBase.Colon + bck);
                }

                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 SchumixPacket();
                packet.Write <int>((int)Opcode.SMSG_AUTH_DENIED);
                packet.Write <int>((int)0);
                SendPacketBack(packet, stream, hst, bck);
            }
            else
            {
                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 SchumixPacket();
                packet.Write <int>((int)Opcode.SMSG_AUTH_APPROVED);
                packet.Write <int>((int)1);
                SendPacketBack(packet, stream, hst, bck);
            }
        }
コード例 #2
0
        public void HandlePacket(SchumixPacket 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 SchumixPacket();
                packet2.Write <int>((int)Opcode.SCMSG_PACKET_NULL);
                packet2.Write <string>(sLConsole.GetString("Wrong packetid, aborting connection!"));
                SendPacketBack(packet2, stream, hst, bck);
                Log.Warning("HandlePacket", sLConsole.GetString("Wrong packetid, aborting connection!"));
                return;
            }

            Log.Debug("HandlePacket", sLConsole.GetString("Got packet with ID: {0} from: {1}"), packetid, client.Client.RemoteEndPoint);

            if (!_AuthList.ContainsKey(hst + SchumixBase.Colon + bck))
            {
                if (packetid != (int)Opcode.CMSG_REQUEST_AUTH)
                {
                    var packet2 = new SchumixPacket();
                    packet2.Write <int>((int)Opcode.SMSG_AUTH_DENIED);
                    packet2.Write <int>((int)0);
                    SendPacketBack(packet2, stream, hst, bck);
                    return;
                }
                else
                {
                    _AuthList.Add(hst + SchumixBase.Colon + bck, true);
                }
            }

            if (!_HostList.ContainsKey(hst + SchumixBase.Colon + bck))
            {
                _HostList.Add(hst + SchumixBase.Colon + bck, stream);
            }

            if (PacketMethodMap.ContainsKey((Opcode)packetid))
            {
                PacketMethodMap[(Opcode)packetid].Method.Invoke(packet, stream, hst, bck);
                return;
            }
            else
            {
                Log.Notice("HandlePacket", sLConsole.GetString("Received unhandled packetid: {0}"), packetid);
            }
        }
コード例 #3
0
        private void ScsRandomHandler(SchumixPacket pck, NetworkStream stream, string hst, int bck)
        {
            var rand   = new Random();
            int random = rand.Next();

            Log.Notice("Random", sLConsole.GetString("Sending random value: {0}"), random);

            var packet = new SchumixPacket();

            packet.Write <int>((int)Opcode.SMSG_SEND_SCS_RANDOM);
            packet.Write <int>(random);
            SendPacketBack(packet, stream, hst, bck);
        }
コード例 #4
0
        public static void Shutdown(Exception eventArgs = null)
        {
            sUtilities.RemovePidFile();
            sListener.Exit        = true;
            Console.CursorVisible = true;

            if (!eventArgs.IsNull())
            {
                Log.Error("Main", sLConsole.GetString("An unhandled exception has been thrown. ({0})"), eventArgs.Message);
                sCrashDumper.CreateCrashDump(eventArgs);
            }

            var packet = new SchumixPacket();

            packet.Write <int>((int)Opcode.SMSG_CLOSE_CONNECTION);
            packet.Write <int>((int)0);
            sServerPacketHandler.SendPacketBackAllHost(packet);

            Thread.Sleep(2000);
            sRuntime.Exit();
        }
コード例 #5
0
ファイル: SchumixBase.cs プロジェクト: corinne1405/Schumix2
        public static void ServerDisconnect(bool Reconnect = true)
        {
            if (!ServerConfig.Enabled)
            {
                return;
            }

            var packet = new SchumixPacket();

            packet.Write <int>((int)Opcode.CMSG_CLOSE_CONNECTION);
            packet.Write <string>(_guid.ToString());
            packet.Write <string>(SchumixConfig.ConfigFile);
            packet.Write <string>(SchumixConfig.ConfigDirectory);
            packet.Write <string>(Encoding.UTF8.BodyName);
            packet.Write <string>(LocalizationConfig.Locale);
            packet.Write <string>(Reconnect.ToString());
            packet.Write <string>(ServerIdentify);
            ClientSocket.SendPacketToSCS(packet);
        }
コード例 #6
0
ファイル: ClientSocket.cs プロジェクト: Schumix/Schumix2
        /// <summary>
        /// Start listening.
        /// </summary>
        public void Socket()
        {
            Log.Notice("ClientSocket", sLConsole.GetString("Successfully started the ClientSocket."));
            Log.Notice("ClientSocket", sLConsole.GetString("Client connection from: {0}"), client.Client.RemoteEndPoint);
            var client_thread = new Thread(new ParameterizedThreadStart(ClientHandler));
            client_thread.Start(client);
            Thread.Sleep(50);

            var packet = new SchumixPacket();
            packet.Write<int>((int)Opcode.CMSG_REQUEST_AUTH);
            packet.Write<string>(SchumixBase.GetGuid().ToString());
            packet.Write<string>(sUtilities.Md5(_password));
            packet.Write<string>(SchumixBase.ServerIdentify);
            SendPacketToSCS(packet);
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: Schumix/Schumix2
        public static void Shutdown(Exception eventArgs = null)
        {
            sUtilities.RemovePidFile();
            sListener.Exit = true;
            Console.CursorVisible = true;

            if(!eventArgs.IsNull())
            {
                Log.Error("Main", sLConsole.GetString("An unhandled exception has been thrown. ({0})"), eventArgs.Message);
                sCrashDumper.CreateCrashDump(eventArgs);
            }

            var packet = new SchumixPacket();
            packet.Write<int>((int)Opcode.SMSG_CLOSE_CONNECTION);
            packet.Write<int>((int)0);
            sServerPacketHandler.SendPacketBackAllHost(packet);

            Thread.Sleep(2000);
            sRuntime.Exit();
        }
コード例 #8
0
        /// <summary>
        /// Handles the packet.
        /// </summary>
        /// <param name='packet'>
        /// Packet.
        /// </param>
        /// <param name='client'>
        /// Client.
        /// </param>
        public void HandlePacket(SchumixPacket packet, TcpClient client)
        {
            var hst = client.Client.RemoteEndPoint.ToString().Split(SchumixBase.Colon)[0];
            int packetid = 0;

            try
            {
                packetid = packet.Read<int>();
            }
            catch(Exception)
            {
                var packet2 = new SchumixPacket();
                packet2.Write<int>((int)Opcode.SCMSG_PACKET_NULL);
                packet2.Write<string>(sLConsole.GetString("Wrong packetid, aborting connection!"));
                ClientSocket.SendPacketToSCS(packet);
                Log.Warning("ClientPacketHandler", sLConsole.GetString("Wrong packetid, aborting connection!"));
                return;
            }

            Log.Debug("ClientPacketHandler", sLConsole.GetString("Got packet with ID: {0} from: {1}"), packetid, client.Client.RemoteEndPoint);

            if(PacketMethodMap.ContainsKey((Opcode)packetid))
            {
                PacketMethodMap[(Opcode)packetid].Method.Invoke(packet, hst);
                return;
            }
            else
                Log.Notice("ClientPacketHandler", sLConsole.GetString("Received unhandled packetid: {0}"), packetid);
        }
コード例 #9
0
ファイル: SchumixBase.cs プロジェクト: Schumix/Schumix2
        public static void ServerDisconnect(bool Reconnect = true)
        {
            if(!ServerConfig.Enabled)
                return;

            var packet = new SchumixPacket();
            packet.Write<int>((int)Opcode.CMSG_CLOSE_CONNECTION);
            packet.Write<string>(_guid.ToString());
            packet.Write<string>(SchumixConfig.ConfigFile);
            packet.Write<string>(SchumixConfig.ConfigDirectory);
            packet.Write<string>(Encoding.UTF8.BodyName);
            packet.Write<string>(LocalizationConfig.Locale);
            packet.Write<string>(Reconnect.ToString());
            packet.Write<string>(ServerIdentify);
            ClientSocket.SendPacketToSCS(packet);
        }
コード例 #10
0
        public void HandlePacket(SchumixPacket 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 SchumixPacket();
                packet2.Write<int>((int)Opcode.SCMSG_PACKET_NULL);
                packet2.Write<string>(sLConsole.GetString("Wrong packetid, aborting connection!"));
                SendPacketBack(packet2, stream, hst, bck);
                Log.Warning("HandlePacket", sLConsole.GetString("Wrong packetid, aborting connection!"));
                return;
            }

            Log.Debug("HandlePacket", sLConsole.GetString("Got packet with ID: {0} from: {1}"), packetid, client.Client.RemoteEndPoint);

            if(!_AuthList.ContainsKey(hst + SchumixBase.Colon + bck))
            {
                if(packetid != (int)Opcode.CMSG_REQUEST_AUTH)
                {
                    var packet2 = new SchumixPacket();
                    packet2.Write<int>((int)Opcode.SMSG_AUTH_DENIED);
                    packet2.Write<int>((int)0);
                    SendPacketBack(packet2, stream, hst, bck);
                    return;
                }
                else
                    _AuthList.Add(hst + SchumixBase.Colon + bck, true);
            }

            if(!_HostList.ContainsKey(hst + SchumixBase.Colon + bck))
                _HostList.Add(hst + SchumixBase.Colon + bck, stream);

            if(PacketMethodMap.ContainsKey((Opcode)packetid))
            {
                PacketMethodMap[(Opcode)packetid].Method.Invoke(packet, stream, hst, bck);
                return;
            }
            else
                Log.Notice("HandlePacket", sLConsole.GetString("Received unhandled packetid: {0}"), packetid);
        }
コード例 #11
0
        private void ScsRandomHandler(SchumixPacket pck, NetworkStream stream, string hst, int bck)
        {
            var rand = new Random();
            int random = rand.Next();
            Log.Notice("Random", sLConsole.GetString("Sending random value: {0}"), random);

            var packet = new SchumixPacket();
            packet.Write<int>((int)Opcode.SMSG_SEND_SCS_RANDOM);
            packet.Write<int>(random);
            SendPacketBack(packet, stream, hst, bck);
        }
コード例 #12
0
        private void AuthRequestPacketHandler(SchumixPacket 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(ServerConfigs.Password))
            {
                if(_HostList.ContainsKey(hst + SchumixBase.Colon + bck))
                    _HostList.Remove(hst + SchumixBase.Colon + bck);

                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 SchumixPacket();
                packet.Write<int>((int)Opcode.SMSG_AUTH_DENIED);
                packet.Write<int>((int)0);
                SendPacketBack(packet, stream, hst, bck);
            }
            else
            {
                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 SchumixPacket();
                packet.Write<int>((int)Opcode.SMSG_AUTH_APPROVED);
                packet.Write<int>((int)1);
                SendPacketBack(packet, stream, hst, bck);
            }
        }