public static void C_CreatePlayerHandler(PacketSession session, IMessage packet) { C_CreatePlayer createPlayerPacket = (C_CreatePlayer)packet; ClientSession clientSession = (ClientSession)session; clientSession.HandleCreatePlayer(createPlayerPacket); }
public static void S_LoginHandler(PacketSession session, IMessage packet)// 로그인 + 캐릭터 목록 { S_Login loginPacket = packet as S_Login; // TODO 로그인 성공/실패 Debug.Log($"loginOK({loginPacket.LoginOk})"); // TODO : 로비에서 캐릭터 목록 보여주고, 선택 if (loginPacket.Players == null || loginPacket.Players.Count == 0) { C_CreatePlayer createPacket = new C_CreatePlayer(); createPacket.Name = $"Player_{Random.Range(0, 10000).ToString("0000")}"; Managers.Network.Send(createPacket); } else { // 무조건 첫번쨰 캐릭터 로그인 LobbyPlayerInfo info = loginPacket.Players[0]; C_EnterGame enterGamePacket = new C_EnterGame(); enterGamePacket.Name = info.Name; Managers.Network.Send(enterGamePacket); } }
public static void C_CreatePlayerHandler(PacketSession session, IMessage packet) { C_CreatePlayer createPlayerPacket = packet as C_CreatePlayer; ClientSession clientSession = session as ClientSession; clientSession.HandleCreatePlayer(createPlayerPacket); }
public static void S_CreatePlayerHandler(PacketSession session, IMessage packet) { S_CreatePlayer createOkPacket = (S_CreatePlayer)packet; if (createOkPacket.Player == null) { C_CreatePlayer createPacket = new C_CreatePlayer(); createPacket.Name = $"Player_{Random.Range(0, 10000).ToString("0000")}"; Managers.Network.Send(createPacket); } else { C_EnterGame enterGamePacket = new C_EnterGame(); enterGamePacket.Name = createOkPacket.Player.Name; Managers.Network.Send(enterGamePacket); } }
public static void S_CreatePlayerHandler(PacketSession session, IMessage packet)// 플레이어 생성 { S_CreatePlayer createOkPacket = packet as S_CreatePlayer; Debug.Log("CreatePlayer"); if (createOkPacket.Player == null) { // 플레이어 만들기 실패 C_CreatePlayer createPacket = new C_CreatePlayer(); createPacket.Name = $"Player_{Random.Range(0, 10000).ToString("0000")}"; Managers.Network.Send(createPacket); } else { C_EnterGame enterGamePacket = new C_EnterGame(); enterGamePacket.Name = createOkPacket.Player.Name; Managers.Network.Send(enterGamePacket); } }
// Step 2 public static void S_LoginHandler(PacketSession session, IMessage packet)// 로그인 + 캐릭터 목록 { S_Login loginPacket = packet as S_Login; ServerSession serverSession = session as ServerSession; if (loginPacket.Players == null || loginPacket.Players.Count == 0) { C_CreatePlayer createPacket = new C_CreatePlayer(); createPacket.Name = $"DummyPlayer_{serverSession.DummyID.ToString("0000")}"; serverSession.Send(createPacket); } else { // 무조건 첫번쨰 캐릭터 로그인 LobbyPlayerInfo info = loginPacket.Players[0]; C_EnterGame enterGamePacket = new C_EnterGame(); enterGamePacket.Name = info.Name; serverSession.Send(enterGamePacket); } }
// Step2 // 로그인 통과 + 캐릭터 목록 public static void S_LoginHandler(PacketSession session, IMessage packet) { S_Login loginPacket = packet as S_Login; ServerSession serverSession = (ServerSession)session; // TODO : 로비 UI에서 케릭터 보여주고, 선택할 수 있도록 if (loginPacket.Players == null || loginPacket.Players.Count == 0) { C_CreatePlayer createPacket = new C_CreatePlayer(); createPacket.Name = $"Player_{serverSession.DummyId.ToString("0000")}"; serverSession.Send(createPacket); } else { // 무조건 첫번째 캐릭터 로그인 LobbyPlayerInfo info = loginPacket.Players[0]; C_EnterGame enterGamePacket = new C_EnterGame(); enterGamePacket.Name = info.Name; serverSession.Send(enterGamePacket); } }
// 로그인 OK + 캐릭터 목록 public static void S_LoginHandler(PacketSession session, IMessage packet) { S_Login loginPacket = (S_Login)packet; Debug.Log($"LoginOk({loginPacket.LoginOk})"); // TODO : 로비 UI에서 캐릭터 보여주고, 선택할 수 있도록 if (loginPacket.Players == null || loginPacket.Players.Count == 0) { C_CreatePlayer createPacket = new C_CreatePlayer(); createPacket.Name = $"Player_{Random.Range(0, 10000).ToString("0000")}"; Managers.Network.Send(createPacket); } else { // 무조건 첫번째 로그인 LobbyPlayerInfo info = loginPacket.Players[0]; C_EnterGame enterGamePacket = new C_EnterGame(); enterGamePacket.Name = info.Name; Managers.Network.Send(enterGamePacket); } }
public void HandleCreatePlayer(C_CreatePlayer createPacket) { // 로비에서만 가능 if (ServerState != PlayerServerState.ServerStateLobby) { return; } using (AppDbContext db = new AppDbContext()) { // 찾는거 딱히 의미없음.. 동시에 같은 이름 올 수 도있음 PlayerDb findPlayer = db.Players .Where(p => p.PlayerName == createPacket.Name) .FirstOrDefault(); if (findPlayer != null) { // 겹치니 못만든다는 뜻으로 null 패킷 보냄 Send(new S_CreatePlayer()); } else { // 기획상의 1렙 스텟 StatInfo stat = null; DataManager.StatDict.TryGetValue(1, out stat); // DB에 플레이어 추가 PlayerDb newPlayerDb = new PlayerDb() { AccountId = AccountDbId, PlayerName = createPacket.Name, Level = stat.Level, Hp = stat.Hp, MaxHp = stat.MaxHp, Attack = stat.Attack, Speed = stat.Speed, TotalExp = 0 }; db.Players.Add(newPlayerDb); bool success = db.SaveChangesEx(); if (success == false) { return; } // 메모리에 추가 LobbyPlayerInfo lobbyPlayer = new LobbyPlayerInfo() { PlayerDbId = newPlayerDb.PlayerDbId, Name = newPlayerDb.PlayerName, StatInfo = new StatInfo() { Level = newPlayerDb.Level, Hp = newPlayerDb.Hp, MaxHp = newPlayerDb.MaxHp, Attack = newPlayerDb.Attack, Speed = newPlayerDb.Speed, TotalExp = newPlayerDb.TotalExp } }; LobbyPlayers.Add(lobbyPlayer); // 성공 전송 S_CreatePlayer newPlayerPacket = new S_CreatePlayer() { Player = new LobbyPlayerInfo() }; newPlayerPacket.Player.MergeFrom(lobbyPlayer); Send(newPlayerPacket); } } }
public static void C_CreatePlayerHandler(PacketSession session, IMessage packet) { C_CreatePlayer enterGamePacket = (C_CreatePlayer)packet; ClientSession clientSession = (ClientSession)session; }
public void HandleCreatePlayer(C_CreatePlayer createPacket) { // TODO : 이런 저런 보안 체크 if (ServerState != PlayerServerState.ServerStateLobby) { return; } using (AppDbContext db = new AppDbContext()) { PlayerDb findPlayer = db.Players .Where(p => p.PlayerName == createPacket.Name).FirstOrDefault(); if (findPlayer != null) { // 이름이 겹친다 Send(new S_CreatePlayer()); } else { // 1레벨 스탯 정보 추출 StatInfo stat = null; DataManager.StatDict.TryGetValue(1, out stat); // DB에 플레이어 만들어줘야 함 PlayerDb newPlayerDb = new PlayerDb() { PlayerName = createPacket.Name, Level = stat.Level, Hp = stat.Hp, MaxHp = stat.MaxHp, Attack = stat.Attack, Speed = stat.Speed, TotalExp = 0, AccountDbId = AccountDbId }; db.Players.Add(newPlayerDb); bool success = db.SaveChangesEx(); if (success == false) { return; } // 메모리에 추가 LobbyPlayerInfo lobbyPlayer = new LobbyPlayerInfo() { PlayerDbId = newPlayerDb.PlayerDbId, Name = createPacket.Name, StatInfo = new StatInfo() { Level = stat.Level, Hp = stat.Hp, MaxHp = stat.MaxHp, Attack = stat.Attack, Speed = stat.Speed, TotalExp = 0 } }; // 메모리에도 들고 있다 LobbyPlayers.Add(lobbyPlayer); // 클라에 전송 S_CreatePlayer newPlayer = new S_CreatePlayer() { Player = new LobbyPlayerInfo() }; newPlayer.Player.MergeFrom(lobbyPlayer); Send(newPlayer); } } }