public void AddSession(Socket s, TcpServer server) { if (IsSession(s)) { Log.Instance().WriteLog("重用套接字.."); } GameSession session = new GameSession(s, server); m_DicSession[s] = session; }
private int walkTime; //下次走路时间戳 #endregion Fields #region Constructors public BaseObject() { // mVisibleList = new Dictionary<uint, BaseObject>(); mVisibleList = new Dictionary<uint, RefreshObject>(); mActionList = new List<GameStruct.Action>(); mPoint = new GameStruct.Point(); type = OBJECTTYPE.NORMAL; gameid = IDManager.CreateId(); session = null; }
public virtual void Dispose() { mVisibleList.Clear(); mActionList.Clear(); if (session != null) { session.Dispose(); session = null; } }
public BaseObject() { // mVisibleList = new Dictionary<uint, BaseObject>(); mVisibleList = new Dictionary <uint, RefreshObject>(); mActionList = new List <GameStruct.Action>(); mPoint = new GameStruct.Point(); type = OBJECTTYPE.NORMAL; gameid = IDManager.CreateId(); session = null; }
public void Run() { int runtime = System.Environment.TickCount; while (true) { if (System.Environment.TickCount - runtime > 300) { break; //超出三百毫秒下次再处理 } SocketInfo info = GetInfo(); if (info == null) { break; } if (info.s == null) { break; } Socket s = info.s; switch (info.type) { case TYPE_ONCONNECT: { // SessionManager.Instance().AddSession(s, GameServer.GetTcpServer()); break; } case TYPE_CLOSE: { // PlayerObject play = UserEngine.Instance().FindPlayerObjectToSocket(s); // SessionManager.Instance().RemoveSession(s); // UserEngine.Instance().RemovePlayObject(play); //if (play != null) // { // play.GetGameSession().Dispose(); // play.SetGameSession(null); //} break; } case TYPE_RECEIVE: { GameBase.Network.GameSession session = info.session; byte[] bydata = new byte[info.data.Length]; Buffer.BlockCopy(info.data, 0, bydata, 0, info.data.Length); session.m_GamePack.ProcessNetData(bydata); // session.m_nLastTime = System.Environment.TickCount; byte[] retdata = session.m_GamePack.GetData(); if (retdata != null) { GameBase.Network.PackIn packin = new GameBase.Network.PackIn(retdata); ushort tag = packin.ReadUInt16(); switch (tag) { case PacketProtoco.C_LOGINUSER: { GameBase.Network.PacketOut packout = new GameBase.Network.PacketOut(session.GetGamePackKeyEx()); byte[] sendbyte = { 0, 1, 59, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,255, 255, 255, 255 }; packout.WriteBuff(sendbyte); sendbyte = packout.Flush(); Program.server.SendData(info.s, sendbyte); break; } } } // SessionManager.Instance().AddNetData(s, info.data, info.data.Length); break; } } } }
public static void OnConnect(Socket s) { GameSession session; lock (_lock_session) { session = new GameSession(s); m_DicSession[s] = session; } //发送key PacketOut packout = new PacketOut(session.GetGamePackKeyEx()); packout.WriteInt16(8); //长度 packout.WriteUInt16(PacketProtoco.S_KEY); packout.WriteInt32(m_Key); byte[] data = packout.Flush(); server.SendData(s, data); }
public static void SendConnectMapServer(GameSession session, int key, int key2) { byte[] defdata = { 232, 16, 67, 3 }; byte[] defdata2 = { 121, 39, 0, 0, 49, 50, 48, 46, 49, 51, 50, 46, 54, 57, 46, 49, 52, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] ipdata = Coding.GetDefauleCoding().GetBytes(m_GameServerIP); PacketOut packout = new PacketOut(session.GetGamePackKeyEx()); packout.WriteUInt16(84); packout.WriteUInt16(PacketProtoco.S_GAMESERVERINFO); packout.WriteInt32(key); packout.WriteInt32(key2); packout.WriteInt32(m_GameServerPort); packout.WriteBuff(defdata); packout.WriteBuff(ipdata); for (int i = 0; i < 28 - ipdata.Length; i++) { packout.WriteByte(0); } packout.WriteBuff(defdata2); defdata = packout.Flush(); server.SendData(session.m_Socket, defdata); }
public void SetGameSession(GameBase.Network.GameSession _session) { session = _session; }