Пример #1
0
        public void SetUserSessionKey(string nm, byte[] sk)
        {
            nm        = nm.ToLower();
            skeys[nm] = sk;

            // ÈÃGameServerÌßµôËû
            Hashtable h = new Hashtable();

            h["Name"] = nm;
            ServerGroup.Send(ServerGroupMessageType.UserLogin, h);
        }
Пример #2
0
        public RealmList(ushort port, string accountPath)
        {
            remote = "RealmList";
            sock   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Bind(new IPEndPoint(IPAddress.Any, port));
            sock.Listen(5);

            accounts = new DBDir(accountPath);

            SetTimerFunction("RealmListTick", 1000, new TimerFunction(OnTick));
            ServerGroup.SetHandle(ServerGroupMessageType.GameServerHeartBeat, new ServerGroupHandler(OnMsgHandler));
            ServerGroup.SetHandle(ServerGroupMessageType.UserQuery, new ServerGroupHandler(OnMsgHandler));
            ServerGroup.SetHandle(ServerGroupMessageType.UserSetChar, new ServerGroupHandler(OnMsgHandler));

            if (LogMessageEvent != null)
            {
                LogMessageEvent("start port={0} account={1} port:" + port + "accounts" + accounts.Count());
            }
        }
Пример #3
0
        void RunMsg(OP code)
        {
            switch (code)
            {
            case OP.CMSG_AUTH_SESSION:                    //   CMSG_AUTH_SESSION
            {
                if (LogMessageEvent != null)
                {
                    LogMessageEvent("CMSG_AUTH_SESSION build=" + inPacket.Seek(2).GetWord());
                }
                Seek(6).Get(out userName);

                pendAuth          = new Hashtable();
                pendAuth["Name"]  = userName;
                pendAuth["Hash"]  = this.GetHashCode();
                pendAuth["Retry"] = (int)0;
                ServerGroup.Send(ServerGroupMessageType.UserQuery, pendAuth);
                SetTimeoutFunction("CMSG_AUTH_SESSION", 500, new TimerFunction(CheckAuth));
            }
            break;

            case OP.CMSG_PING:
                Send(OP.SMSG_PONG, Seek(2).GetArray(4));
                break;

            default:
            {
                DoMessageFunction h = handler[code] as DoMessageFunction;
                if (h == null)
                {
                    gameServer.LogMessage("UNKNOWN OP: ", code.ToString(), (ushort)code, inPacket.Length);
                    Send(OP.MSG_NULL_ACTION, new byte[] { 0, (byte)code, (byte)((ushort)code >> 8) });
                }
                else
                {
                    h(code, this);
                }
                break;
            }
            }
        }
Пример #4
0
        public void StartServerThread()
        {
            Console.WriteLine("eWoW " + eWoWClass.version + "(c) DjAli");
            XmlSerializer serializer = new XmlSerializer(typeof(ServerConfig));
            ServerConfig  srvconf    = (ServerConfig)serializer.Deserialize(XmlReader.Create("eWoW.config"));

            #region if check
#if CHECK
            StreamWriter w = new StreamWriter("op.txt", false);
            for (ushort c = 0; c <= (ushort)OP.NUM_MSG_TYPES; c++)
            {
                string msg = ((OP)c).ToString() + ",";
                if (msg.Length < 40)
                {
                    msg += new string(' ', 40 - msg.Length);
                }
                w.WriteLine("    {0} // = 0x{1:X}", msg, c);
            }
            w.Close();

            Hashtable mt = new Hashtable();
            foreach (MemberInfo m in typeof(UpdateFields).GetMembers())
            {
                FieldInfo f = m as FieldInfo;
                if (f == null || !f.IsStatic)
                {
                    continue;
                }
                ushort v   = (ushort)f.GetValue(null);
                string n   = m.Name;
                int    pos = n.IndexOf('_');
                if (pos < 0)
                {
                    continue;
                }

                Hashtable h = mt[n.Substring(0, pos)] as Hashtable;
                if (h == null)
                {
                    h = new Hashtable();
                    mt[n.Substring(0, pos)] = h;
                }
                if (h.Contains(v))
                {
                    h[v] = (h[v] as string) + "," + m.Name;
                }
                else
                {
                    h[v] = m.Name;
                }
            }

            w = new StreamWriter("up.txt", false);
            foreach (string k in new string[] { "OBJECT", "ITEM", "CONTAINER", "UNIT", "PLAYER", "GAMEOBJECT", "DYNAMICOBJECT", "CORPSE" })
            {
                Hashtable h     = mt[k] as Hashtable;
                ArrayList datav = new ArrayList();
                datav.AddRange(h.Keys);
                datav.Sort();

                w.WriteLine("");
                w.WriteLine("    // {0}", k);

                string begin  = null;
                ushort beginv = 0;
                for (int i = 0; i < datav.Count; i++)
                {
                    ushort v  = (ushort)datav[i];
                    string ns = h[v] as String;

                    foreach (string _n in ns.Split(','))
                    {
                        string n = _n;
                        if (n.Length < 30)
                        {
                            n += new string(' ', 30 - n.Length);
                        }

                        if (begin == null)
                        {
                            w.WriteLine("    {0} = 0x{1:X}, // pos={1}", n, v);
                        }
                        else if (i < datav.Count - 1)
                        {
                            int size = (ushort)datav[i + 1] - (ushort)datav[i];
                            w.WriteLine("    {0} = 0x{1:X} + {2}, // size={3}, pos={4}", n, v - beginv, begin, size, v);
                        }
                        else
                        {
                            w.WriteLine("    {0} = 0x{1:X} + {2}, // pos={3}", n, v - beginv, begin, v);
                        }

                        if (begin == null)
                        {
                            begin  = n.Trim();
                            beginv = v;
                        }
                    }
                }
            }
            w.Close();
#endif
            #endregion end if check
            ServerGroup.Start(srvconf.RealmListPort);

            url = srvconf.Address;


            if (IPAddress.Parse(Ip.ToString()).Equals(IPAddress.Loopback))
            {
                RealmList rserver = new RealmList(srvconf.RealmListPort, "accounts");
                rserver.LogMessageEvent += new eWoW.RealmList.LogMessageHandler(rserver_LogMessageEvent);
                NetWork.Add(rserver);
            }

            //if(gameServer!=null)return;
            //new IPEndPoint(IPAddress.Parse(r["ws_host"] as string), ushort.Parse(r["ws_port"] as string)), ".", db
            System.Net.IPEndPoint addr = new IPEndPoint(Ip, srvconf.WorldServerPort);
            string path = ".";
            gameServer = new GameServer();
            gameServer.LogMessageEvent += new eWoW.GameServer.LogMessageHandler(gameServer_LogMessageEvent);
            gameServer.Start(addr, path, srvconf);
            NetWork.Add(gameServer);

            //GameServer.Start( );
            srvconf = null;

            if (ServerStarted != null)
            {
                ServerStarted();
            }
            NetWork.Run();
            if (ServerStopped != null)
            {
                ServerStopped();
            }
            if (LogMessageEvent != null)
            {
                LogMessageEvent("SYSTEM" + "stop");
            }
        }
Пример #5
0
        void OnTick()
        {
            ArrayList allObjs = new ArrayList();

            allObjs.AddRange(objs.Values);
            foreach (ObjWithPosition ob in allObjs)
            {
                ob.UpdateInRange(allObjs, objRemove);
            }

            if (clients.Count > 0)
            {
                ArrayList remove = new ArrayList();
                foreach (PlayerConnection p in clients)
                {
                    if (!p.Connected())
                    {
                        remove.Add(p);
                    }
                }
                foreach (PlayerConnection p in remove)
                {
                    clients.Remove(p);
                }

                foreach (PlayerConnection p in clients)
                {
                    if (p.player == null)
                    {
                        continue;
                    }
                    p.player.BuildUpdateForSet();
                }

                foreach (PlayerConnection p in clients)
                {
                    if (p.player == null)
                    {
                        continue;
                    }
                    p.player.SendUpdate(false);
                }
            }

            // clear objs
            foreach (ObjWithPosition ob in objRemove)
            {
                objs.Remove(ob.GUID);
            }
            objRemove.Clear();

            // GameServerHeartBeat

            Hashtable svr = new Hashtable();

            svr["Name"]      = name;
            svr["Type"]      = type; // Jedna se o typ serveru PVP nebo pve nebo rp
            svr["Address"]   = sock.LocalEndPoint.ToString();
            svr["UserCount"] = (uint)clients.Count;
            ServerGroup.Send(ServerGroupMessageType.GameServerHeartBeat, svr);

            if (tickSave > 0 && tickSave <= Const.Tick)
            {
                SaveWorld();
                tickSave = Const.Tick + 600 * 1000;
            }

            System.GC.Collect();

            if ((nextGUID & (1 << Const.GUID_BITS)) != 0)
            {
                NetWork.Stop = true;
            }
        }
Пример #6
0
        public void OnMsgHandler(ServerGroupMessageType type, Hashtable msg)
        {
            if (type == ServerGroupMessageType.GameServerHeartBeat)
            {
                string nm = msg["Name"] as string;
                if (nm == null)
                {
                    return;
                }

                msg["UpdateTick"] = Const.Tick;
                servers[nm]       = msg;
            }

            // GameServer ask username & SessionKey
            if (type == ServerGroupMessageType.UserQuery)
            {
                string nm = msg["Name"] as string;
                if (nm == null)
                {
                    return;
                }
                nm = nm.ToLower();


                Hashtable user = accounts.Get(nm);
                if (user == null)
                {
                    return;
                }

                if (skeys.Contains(nm))
                {
                    user["SESSIONKEY"] = skeys[nm];
                }
                user["Hash"] = msg["Hash"];
                ServerGroup.Send(ServerGroupMessageType.UserReply, user);
            }
            if (type == ServerGroupMessageType.UserSetChar)
            {
                string nm = msg["Name"] as string;
                if (nm == null)
                {
                    return;
                }
                nm = nm.ToLower();


                Hashtable user = accounts.Get(nm);
                if (user == null)
                {
                    return;
                }

                foreach (string n in msg.Keys)
                {
                    if (!n.StartsWith("CHAR "))
                    {
                        continue;
                    }
                    user[n] = msg[n];
                }
                accounts.Set(nm, user);
            }
        }