void CheckAuth() { if (pendAuth == null) { return; } if (pendAuth.Contains("Retry")) { int r = (int)pendAuth["Retry"]; if (r > 3) { pendAuth = null; Dispose(); return; } // È¡ CHAR ³¬Ê± ServerGroup.Send(ServerGroupMessageType.UserQuery, pendAuth); SetTimeoutFunction("CMSG_AUTH_SESSION", 500, new TimerFunction(CheckAuth)); return; } SS_Hash = pendAuth["SESSIONKEY"] as Byte[]; if (SS_Hash == null) { Send(OP.SMSG_AUTH_RESPONSE, new byte[] { 21 }); SetTimeoutFunction("CMSG_AUTH_SESSION", 1000, new TimerFunction(Dispose)); return; } new CharacterHandler(gameServer, this, pendAuth["CHAR"] as string); pendAuth = null; Send(OP.SMSG_AUTH_RESPONSE, new byte[] { 12 }); }
public void SetChar(string userName, string chars) { Hashtable svr = new Hashtable(); svr["Name"] = userName; svr["CHAR " + name] = chars; ServerGroup.Send(ServerGroupMessageType.UserSetChar, svr); }
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); }
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; } } }
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; } }
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); } }