protected void C2G_Hello(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2G_Hello>(); Debug.Log("C2G_Hello" + msg); var userInfo = msg.UserInfo; if (userInfo == null) { return; } var room = _roomId2Rooms.GetRefVal(msg.RoomId); if (room != null && room.GameType == msg.GameType && room.GameHash == msg.GameHash ) { var localId = room.CheckAndGetUserLocalId(userInfo); if (localId != -1) { var player = room.Players[localId]; player.Peer = reader.Peer; reader.Peer.AddExtension(player); reader.Respond(EMsgSC.G2C_Hello, new Msg_G2C_Hello() { MapId = room.MapId, LocalId = (byte)localId }); return; } } reader.Respond(1, EResponseStatus.Failed); }
protected void L2G_StartGame(IIncommingMessage reader) { var msg = reader.Parse <Msg_L2G_StartGame>(); Debug.Log("L2G_StartGame" + msg); var room = Pool.Get <GameRoom>(); var roomId = CurRoomId++; room.GameType = msg.GameType; room.GameHash = msg.GameHash; room.MapId = msg.MapId; var count = msg.Players.Length; var players = new Player[count]; for (int i = 0; i < count; i++) { var user = msg.Players[i]; var player = Pool.Get <Player>(); player.UserId = user.UserId; player.Account = user.Account; player.LoginHash = user.LoginHash; player.LocalId = (byte)i; players[i] = player; } room.Players = players; room.Init(); _roomId2Rooms.Add(roomId, room); reader.Respond(roomId, EResponseStatus.Success); }
protected void C2L_CreateRoom(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_CreateRoom>(); var user = reader.Peer.GetExtension <User>(); if (user?.Room != null) { reader.Respond(1, EResponseStatus.Failed); return; } Debug.Log("AddRoom " + msg); var room = AddRoom(user, msg.Name, msg.MapId, msg.MaxPlayerCount); reader.Respond(EMsgSC.L2C_CreateRoomResult, new Msg_L2C_CreateRoom() { Info = room.Info, PlayerInfos = room.RoomPlayerInfos }); var bMsg = MessageHelper.Create((short)EMsgSC.L2C_RoomInfoUpdate, new Msg_L2C_RoomInfoUpdate() { AddInfo = new RoomInfo[] { room.Info } }); BorderMessage(bMsg, user.GameType, ELobbyBorderType.OutRoom); }
protected void C2I_UserLogin(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2I_UserLogin>(); Debug.Log("C2I_UserLogin" + msg); ReqUserInfo(msg, reader); }
protected void C2G_UdpHello(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2G_UdpHello>().Hello; Debug.Log("C2G_UdpHello" + msg + " id" + reader.Peer.Id); var userInfo = msg.UserInfo; if (userInfo == null) { return; } var game = _gameId2Games.GetRefVal(msg.GameId); if (game != null && game.GameType == msg.GameType && game.GameHash == msg.GameHash ) { var localId = game.GetUserLocalId(userInfo.UserId); if (localId != -1) { var player = game.Players[localId]; if (player.LoginHash == userInfo.LoginHash) { player.PeerUdp = reader.Peer; reader.Peer.AddExtension(player); reader.Respond(EMsgSC.G2C_UdpHello, new Msg_G2C_Hello() { MapId = game.MapId, LocalId = (byte)localId }); } } } }
protected void G2L_OnGameFinished(IIncommingMessage reader) { var msg = reader.Parse <Msg_G2L_OnGameFinished>(); var roomId = msg.RoomId; if (_roomId2Room.TryGetValue(roomId, out var room)) { Debug.Log("OnGameFinished " + msg); foreach (var user in room.Users.ToArray()) { room.RemoveUser(user); user.Room = null; } var bMsg = MessageHelper.Create((short)EMsgSC.L2C_RoomInfoUpdate, new Msg_L2C_RoomInfoUpdate() { DeleteInfo = new int[] { room.RoomId } }); BorderMessage(bMsg, room.GameType, ELobbyBorderType.OutRoom); RemoveRoom(room); } else { Debug.LogError("Room Finished but room destroyed? " + roomId); } }
protected void C2L_CreateRoom(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_CreateRoom>(); var user = reader.Peer.GetExtension <User>(); if (user?.Room != null) { reader.Respond(1, EResponseStatus.Failed); return; } Debug.Log("AddRoom " + msg); var room = AddRoom(user, msg.Name, msg.MapId, msg.MaxPlayerCount); reader.Respond(EMsgSC.L2C_CreateRoomResult, new Msg_L2C_CreateRoom() { Info = room.Info, PlayerInfos = room.RoomPlayerInfos }); //TODO 缓存信息 批量发送 if (_gameType2Rooms.TryGetValue(user.GameType, out var rooms)) { var bytes = new Msg_L2C_RoomInfoUpdate() { AddInfo = new RoomInfo[] { room.Info } }.ToBytes(); //var bMsg = MessageHelper.Create((short) EMsgSC.L2C_RoomInfoUpdate,); foreach (var tRoom in rooms) { tRoom.BorderMessage((short)EMsgSC.L2C_RoomInfoUpdate, bytes); } } }
protected void G2C_AllFinishedLoaded(IIncommingMessage reader) { var msg = reader.Parse <Msg_G2C_AllFinishedLoaded>(); curLevel = msg.Level; _handler.OnAllFinishedLoaded(msg.Level); }
protected void S2D_ReqCreateUser(IIncommingMessage reader) { var msg = reader.Parse <Msg_CreateAccount>(); _authDb.GetAccount(msg.account, (dbData) => { if (dbData == null) { var newInfo = _authDb.CreateAccountObject(); newInfo.Username = msg.account; newInfo.Password = msg.password; newInfo.Email = "null" + LRandom.Next(); newInfo.Token = "aaa"; newInfo.IsAdmin = true; newInfo.IsGuest = false; newInfo.IsEmailConfirmed = false; _authDb.InsertNewAccount(newInfo , (userId) => { reader.Respond(EMsgDS.D2S_RepCreateUser, new Msg_RepCreateResult() { result = 0, userId = userId }); }); } else { reader.Respond(EMsgDS.D2S_RepCreateUser, new Msg_RepCreateResult() { result = 1 }); } }); }
protected void S2D_SaveGameData(IIncommingMessage reader) { var msg = reader.Parse <Msg_S2D_SaveGameData>(); _authDb.UpdateGameData(msg.data, () => { reader.Respond(1, EResponseStatus.Success); }); }
protected void G2C_GameStartInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_G2C_GameStartInfo>(); Log("G2C_GameStartInfo " + msg); HasRecvGameDta = true; GameStartInfo = msg; _handler.OnGameStartInfo(msg); }
protected void S2M_RegisterServer(IIncommingMessage reader) { var net = new ServerProxy(reader.Peer); reader.Peer.AddExtension(net); var msg = reader.Parse <Msg_RegisterServer>(); net.ServerType = (EServerType)msg.ServerInfo.ServerType; }
protected void C2L_JoinRoom(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_JoinRoom>(); Debug.Log("C2L_JoinRoom" + msg); var roomId = msg.RoomId; if (_roomId2Room.TryGetValue(roomId, out var room)) { if (room.IsFull || room.IsPlaying) { reader.Respond((int)ERoomOperatorResult.Full, EResponseStatus.Failed); return; } else { var user = reader.Peer.GetExtension <User>(); if (user?.Room == null) { user.Room = room; room.AddUser(user); reader.Respond((short)EMsgSC.L2C_JoinRoomResult, new Msg_L2C_JoinRoomResult() { PlayerInfos = room.RoomPlayerInfos }); room.BorderMessage((short)EMsgSC.L2C_JoinRoom, new Msg_L2C_JoinRoom() { PlayerInfo = new RoomPlayerInfo() { UserId = user.UserId, Name = user.Name, Status = user.IsReady } }); var bMsg = MessageHelper.Create((short)EMsgSC.L2C_RoomInfoUpdate, new Msg_L2C_RoomInfoUpdate() { ChangedInfo = new RoomChangedInfo[] { new RoomChangedInfo() { RoomId = room.RoomId, CurPlayerCount = room.CurPlayerCount } } }); BorderMessage(bMsg, user.GameType, ELobbyBorderType.OutRoom); } else { reader.Respond((int)ERoomOperatorResult.AlreadyExist, EResponseStatus.Failed); } } } else { reader.Respond((int)ERoomOperatorResult.NotExist, EResponseStatus.Failed); } }
protected void C2L_LeaveRoom(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_LeaveRoom>(); var user = reader.Peer.GetExtension <User>(); if (user?.Room == null) { return; } var room = user.Room; room.RemoveUser(user); if (room.IsEmpty) { var roomId = user.Room.RoomId; //TODO 缓存 if (_gameType2Rooms.TryGetValue(user.GameType, out var rooms)) { //var bMsg = MessageHelper.Create((short) EMsgSC.L2C_RoomInfoUpdate, // new Msg_L2C_RoomInfoUpdate() { // DeleteInfo = new[] {roomId} // }.ToBytes()); //foreach (var tRoom in rooms) { // tRoom.BorderMessage(bMsg); //} var bytes = new Msg_L2C_RoomInfoUpdate() { DeleteInfo = new[] { roomId } }.ToBytes(); //var bMsg = MessageHelper.Create((short) EMsgSC.L2C_RoomInfoUpdate,); foreach (var tRoom in rooms) { tRoom.BorderMessage((short)EMsgSC.L2C_RoomInfoUpdate, bytes); } } RemoveRoom(user.Room); reader.Respond((int)ERoomOperatorResult.Succ, EResponseStatus.Success); user.Room = null; return; } if (room.Owner == user) { room.Owner = room.Users[0]; } user.Room = null; reader.Respond((int)ERoomOperatorResult.Succ, EResponseStatus.Success); room.BorderMessage((short)EMsgSC.L2C_LeaveRoom, new Msg_L2C_LeaveRoom() { UserId = user.UserId }); }
protected void L2G_UserLeave(IIncommingMessage reader) { var msg = reader.Parse <Msg_L2G_UserLeave>(); Log("L2G_UserLeave " + msg); if (_gameId2Games.TryGetValue(msg.GameId, out var game)) { game.OnPlayerLeave(msg.UserId); } }
protected void G2L_RegisterServer(IIncommingMessage reader) { var msg = reader.Parse <Msg_RegisterServer>(); if (!_peerId2Servers.ContainsKey(reader.Peer.Id)) { _peerId2Servers[reader.Peer.Id] = reader.Peer; reader.Peer.AddExtension(msg.ServerInfo); _allGameServers.Add(reader.Peer); } }
public void X2S_BorderMasterInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_BorderMasterInfo>(); if (msg.ServerInfo.ServerType == (byte)serverType) { InitClientMS(msg.ServerInfo); } OnMasterServerInfo(msg.ServerInfo); }
protected void M2Y_RegisterServerInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_RegisterServer>(); var oServerType = (EServerType)msg.ServerInfo.ServerType; if (!_type2MasterPeer.TryGetValue(oServerType, out var info)) { _type2MasterPeer.Add(oServerType, reader.Peer); _type2MasterInfo[oServerType] = msg.ServerInfo; } }
protected void C2L_RoomChatInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_RoomChatInfo>(); Debug.Log("C2L_RoomChatInfo" + msg); var user = reader.Peer.GetExtension <User>(); user?.Room?.BorderMessage((short)EMsgSC.L2C_RoomChatInfo, new Msg_L2C_RoomChatInfo() { ChatInfo = msg.ChatInfo }); }
//TODO CacheInfo protected void S2D_ReqGameData(IIncommingMessage reader) { var msg = reader.Parse <Msg_S2D_ReqGameData>(); _authDb.GetGameData(msg.account, (dbData) => { reader.Respond(EMsgDS.D2S_RepGameData, new Msg_D2S_RepGameData() { data = dbData as GameData }); }); }
protected void S2D_ReqUserInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_ReqAccountData>(); _authDb.GetAccount(msg.account, (dbData) => { reader.Respond(EMsgDS.D2S_RepUserInfo, new Msg_RepAccountData() { accountData = dbData as AccountData }); }); }
protected void C2L_LeaveRoom(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_LeaveRoom>(); var user = reader.Peer.GetExtension <User>(); if (user?.Room == null) { return; } var room = user.Room; room.RemoveUser(user); if (room.IsEmpty) { var roomId = room.RoomId; user.Room = null; //TODO 缓存 var bMsg = MessageHelper.Create((short)EMsgSC.L2C_RoomInfoUpdate, new Msg_L2C_RoomInfoUpdate() { DeleteInfo = new[] { roomId } }); BorderMessage(bMsg, user.GameType, ELobbyBorderType.OutRoom); RemoveRoom(room); reader.Respond((int)ERoomOperatorResult.Succ, EResponseStatus.Success); return; } if (room.Owner == user) { room.Owner = room.Users[0]; } user.Room = null; reader.Respond((int)ERoomOperatorResult.Succ, EResponseStatus.Success); room.BorderMessage((short)EMsgSC.L2C_LeaveRoom, new Msg_L2C_LeaveRoom() { UserId = user.UserId }); { var bMsg = MessageHelper.Create((short)EMsgSC.L2C_RoomInfoUpdate, new Msg_L2C_RoomInfoUpdate() { ChangedInfo = new RoomChangedInfo[] { new RoomChangedInfo() { RoomId = room.RoomId, CurPlayerCount = room.CurPlayerCount } } }); BorderMessage(bMsg, user.GameType, ELobbyBorderType.OutRoom); } }
protected void S2X_ReqMasterInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_ReqMasterInfo>(); var proxy = new ServerProxy(reader.Peer); reader.Peer.AddExtension(proxy); proxy.ServerType = (EServerType)msg.ServerInfo.ServerType; msg.ServerInfo.Ip = proxy.EndPoint.Address.ToString(); _netClientYX.SendMessage(EMsgYX.X2Y_ReqMasterInfo, msg, (status, respond) => { var respondMsg = respond.Parse <Msg_RepMasterInfo>(); reader.Respond(respondMsg); }); }
protected void L2G_CreateGame(IIncommingMessage reader) { var msg = reader.Parse <Msg_L2G_CreateGame>(); var game = CreateGame(msg.GameType) as BaseGame; if (game == null) { reader.Respond(-1, EResponseStatus.Failed); return; } game.TcpEnd = TcpEnd; game.UdpEnd = UdpEnd; game.RoomId = msg.RoomId; Debug.Log("L2G_CreateGame" + msg); var gameId = CurGameId++; _gameId2Games.Add(gameId, game); _cachedBaseGames = null; game.DoStart(this, gameId, msg.GameType, msg.MapId, msg.Players, msg.GameHash); var players = game.Players; foreach (var player in players) { _uid2Players[player.UserId] = player; //get game data from database _netClientDS.SendMessage(EMsgDS.S2D_ReqGameData, new Msg_S2D_ReqGameData() { account = player.Account }, (status, respond) => { var rMsg = respond.Parse <Msg_D2S_RepGameData>(); Debug.Log("Msg_D2S_RepGameData" + rMsg); if (_uid2Players.TryGetValue(player.UserId, out var user)) { user.GameData = rMsg.data; if (user.Game != null && user.Game.GameId == gameId) //防止玩家重新进入房间 { user.Game.OnRecvPlayerGameData(user); } } } ); } //Load dlls reader.Respond(gameId, EResponseStatus.Success); }
protected void S2M_ReqOtherServerInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_ReqOtherServerInfo>(); var type = (EServerType)msg.ServerType; if (type == serverType) { //TODO var info = GetSlaveServeInfo(msg.DetailType); reader.Respond(EMsgMS.M2S_RepOtherServerInfo, new Msg_RepOtherServerInfo() { ServerInfo = info }); } }
protected void C2L_ReqRoomList(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_ReqRoomList>(); var user = reader.Peer.GetExtension <User>(); var startIdx = msg.StartIdx; if (user != null) { var infos = GetRoomInfos(user.GameType); user.SendMessage((short)EMsgSC.L2C_RoomList, new Msg_L2C_RoomList() { Rooms = infos }); } }
protected void C2G_Hello(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2G_Hello>().Hello; Debug.Log("C2G_Hello" + msg + " id" + reader.Peer.Id); var userInfo = msg.UserInfo; if (userInfo == null) { return; } var game = _gameId2Games.GetRefVal(msg.GameId); if (game != null && game.GameType == msg.GameType && game.GameHash == msg.GameHash ) { var localId = game.GetUserLocalId(userInfo.UserId); if (localId != -1) { var player = game.Players[localId]; if (player.LoginHash == userInfo.LoginHash) { player.PeerTcp = reader.Peer; _peerId2Player[reader.Peer.Id] = player; reader.Peer.AddExtension(player); reader.Respond(EMsgSC.G2C_Hello, new Msg_G2C_Hello() { LocalId = (byte)localId, UserCount = (byte)game.MaxPlayerCount, MapId = game.MapId, GameId = game.GameId, Seed = game.Seed, UdpEnd = new IPEndInfo() { Ip = this.Ip, Port = _serverConfig.udpPort } }); game.OnPlayerConnect(player); return; } } } reader.Respond(1, EResponseStatus.Failed); }
protected void I2L_UserLogin(IIncommingMessage reader) { var msg = reader.Parse <Msg_I2L_UserLogin>(); if (_uid2Player.TryGetValue(msg.UserId, out var oldPlayer)) { oldPlayer.LoginHash = msg.LoginHash; oldPlayer.GameType = msg.GameType; } else { AddPlayer(reader.Peer, msg.UserId, msg.GameType, msg.Account, msg.Account, msg.LoginHash); } reader.Respond(1, EResponseStatus.Success); }
protected void C2L_JoinRoom(IIncommingMessage reader) { var msg = reader.Parse <Msg_C2L_JoinRoom>(); Debug.Log("C2L_JoinRoom" + msg); var roomId = msg.RoomId; if (_roomId2Room.TryGetValue(roomId, out var room)) { if (room.IsFull) { reader.Respond((int)ERoomOperatorResult.Full, EResponseStatus.Failed); return; } else { var user = reader.Peer.GetExtension <User>(); if (user.Room == null) { user.Room = room; room.AddUser(user); reader.Respond((short)EMsgSC.L2C_JoinRoomResult, new Msg_L2C_JoinRoomResult() { PlayerInfos = room.RoomPlayerInfos }); room.BorderMessage((short)EMsgSC.L2C_JoinRoom, new Msg_L2C_JoinRoom() { PlayerInfo = new RoomPlayerInfo() { UserId = user.UserId, Name = user.Name, Status = user.IsReady } }); } else { reader.Respond((int)ERoomOperatorResult.AlreadyExist, EResponseStatus.Failed); } } } else { reader.Respond((int)ERoomOperatorResult.NotExist, EResponseStatus.Failed); } }
protected void X2Y_ReqOtherServerInfo(IIncommingMessage reader) { var msg = reader.Parse <Msg_ReqOtherServerInfo>(); if (_type2MasterPeer.TryGetValue((EServerType)msg.ServerType, out var peer)) { peer.SendMessage((short)EMsgYM.Y2M_ReqOtherServerInfo, msg, (status, respond) => { var rMsg = respond.Parse <Msg_RepOtherServerInfo>(); reader.Respond(rMsg); }); } else { reader.Respond(0, EResponseStatus.Failed); } }