Exemplo n.º 1
0
        // Update Listener Cache Database
        public void UpdateLCDB(string Sql)
        {
            lock(ListenerLock)
            {
                if(!ListenerConfig.Enabled)
                    return;

                var packet = new ListenerPacket();
                packet.Write<int>((int)ListenerOpcode.SMSG_UPDATE_DB);
                packet.Write<string>(Sql);
                sSchumixPacketHandler.SendPacketBackAllHost(packet);
            }
        }
Exemplo n.º 2
0
        public static void ListenerDisconnect()
        {
            if (!ListenerConfig.Enabled)
            {
                return;
            }

            var packet = new ListenerPacket();

            packet.Write <int>((int)ListenerOpcode.SMSG_CLOSE_CONNECTION);
            packet.Write <string>(sLConsole.GetString("Schumix Shutdown"));
            sSchumixPacketHandler.SendPacketBackAllHost(packet);
        }
Exemplo n.º 3
0
        // Update Listener Cache Database
        public void UpdateLCDB(string Sql)
        {
            lock (ListenerLock)
            {
                if (!ListenerConfig.Enabled)
                {
                    return;
                }

                var packet = new ListenerPacket();
                packet.Write <int>((int)ListenerOpcode.SMSG_UPDATE_DB);
                packet.Write <string>(Sql);
                sSchumixPacketHandler.SendPacketBackAllHost(packet);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 private void SchumixVersionHandler(ListenerPacket pck, NetworkStream stream, string hst, int bck)
 {
     var packet = new ListenerPacket();
     packet.Write<int>((int)ListenerOpcode.SMSG_SCHUMIX_VERSION);
     packet.Write<string>(sUtilities.GetVersion());
     SendPacketBack(packet, stream, hst, bck);
 }
Exemplo n.º 6
0
        private void PongHandler(ListenerPacket pck, NetworkStream stream, string hst, int bck)
        {
            _HostList[hst + SchumixBase.Colon + bck].LastPing = DateTime.Now;

            var packet = new ListenerPacket();
            packet.Write<int>((int)ListenerOpcode.SMSG_PONG);
            SendPacketBack(packet, stream, hst, bck);
        }
Exemplo n.º 7
0
        private void HandlePingTimer(object sender, ElapsedEventArgs e)
        {
            var rlist = new  Dictionary<string, Host>();

            foreach(var list in _HostList)
            {
                if((DateTime.Now - list.Value.LastPing).Minutes >= 5) // 5 minute
                {
                    rlist.Add(list.Key, list.Value);
                    var packet = new ListenerPacket();
                    packet.Write<int>((int)ListenerOpcode.SMSG_CLOSE_CONNECTION);
                    packet.Write<string>(sLConsole.GetString("Ping Timeout"));
                    SendPacketBack(packet, list.Value.Stream, list.Key.Split(SchumixBase.Colon)[0], list.Key.Split(SchumixBase.Colon)[1].ToInt32());
                    Log.Warning("HandlePingTimer", sLConsole.GetString("Connection closed! Guid of client: {0}"), list.Value.Guid);
                }
            }

            foreach(var l in rlist)
            {
                if(_HostList.ContainsKey(l.Value.Hst + SchumixBase.Colon + l.Value.Bck))
                    _HostList.Remove(l.Value.Hst + SchumixBase.Colon + l.Value.Bck);

                if(_AuthList.ContainsKey(l.Value.Hst + SchumixBase.Colon + l.Value.Bck))
                    _AuthList.Remove(l.Value.Hst + SchumixBase.Colon + l.Value.Bck);
            }

            if(rlist.Count > 0)
                rlist.Clear();

            foreach(var list in _HostList)
            {
                var packet = new ListenerPacket();
                packet.Write<int>((int)ListenerOpcode.SMSG_PING);
                packet.Write<long>((long)sUtilities.UnixTime);
                SendPacketBack(packet, list.Value.Stream, list.Key.Split(SchumixBase.Colon)[0], list.Key.Split(SchumixBase.Colon)[1].ToInt32());
            }
        }
Exemplo n.º 8
0
        private void CacheDBHandler(ListenerPacket pck, NetworkStream stream, string hst, int bck)
        {
            var db = SchumixBase.DManager.Query("SELECT Id, ServerId, ServerName, Name, Password, Vhost, Flag FROM admins");
            if(!db.IsNull())
            {
                int i = 0;
                var packet = new ListenerPacket();
                packet.Write<int>((int)ListenerOpcode.SMSG_CACHE_DB);

                foreach(DataRow row in db.Rows)
                {
                    i++;
                    int Id = row["Id"].ToInt32();
                    int ServerId = row["ServerId"].ToInt32();
                    string ServerName = row["ServerName"].ToString();
                    string Name = row["Name"].ToString();
                    string Password = row["Password"].ToString();
                    string Vhost = row["Vhost"].ToString();
                    int Flag = row["Flag"].ToInt32();
                    packet.Write<string>(string.Format("INSERT INTO `admins` VALUES (\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\"", Id, ServerId, ServerName, Name, Password, Vhost, Flag));
                }

                if(i > 0)
                    SendPacketBack(packet, stream, hst, bck);
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        public static void ListenerDisconnect()
        {
            if(!ListenerConfig.Enabled)
                return;

            var packet = new ListenerPacket();
            packet.Write<int>((int)ListenerOpcode.SMSG_CLOSE_CONNECTION);
            packet.Write<string>(sLConsole.GetString("Schumix Shutdown"));
            sSchumixPacketHandler.SendPacketBackAllHost(packet);
        }