public void RpcBroadcastPlayername(uint playerID, string name) { LobbyPlayerInfo lpi = NetworkManagerV2.single.GetLobbyPlayer(playerID); lpi.lobbyPlayer.playerName = name; lpi.UiIcon.Init(name); }
public void AddCharacterActor(LobbyPlayerInfo playerInfo) { CharacterResourceLink resourceLink = GameWideData.Get().GetCharacterResourceLink(playerInfo.CharacterType); Log.Info($"Add Character {resourceLink.GetDisplayName()} for player {playerInfo.Handle}"); GameObject atsdObject = SpawnObject("ActorTeamSensitiveData_Friendly", false); GameObject character = GameObject.Instantiate(resourceLink.ActorDataPrefab); ActorData actorData = character.GetComponent <ActorData>(); ActorTeamSensitiveData atsd = atsdObject.GetComponent <ActorTeamSensitiveData>(); actorData.SetupAbilityMods(playerInfo.CharacterInfo.CharacterMods); //# actorData.PlayerIndex = playerInfo.PlayerId; actorData.ActorIndex = playerInfo.PlayerId; atsd.SetActorIndex(actorData.ActorIndex); // PATCH private -> public ActorTeamSensitiveData.SetActorIndex PlayerData playerData = character.GetComponent <PlayerData>(); playerData.PlayerIndex = playerInfo.PlayerId; actorData.SetTeam(playerInfo.TeamId); actorData.UpdateDisplayName(playerInfo.Handle); actorData.SetClientFriendlyTeamSensitiveData(atsd); NetworkServer.Spawn(atsdObject); NetworkServer.Spawn(character); // For some reason, when you spawn atsd first, you see enemy characters, and when you spawn character first, you don't // They get lost because enemies are not YET registered in GameFlowData actors when TeamSensitiveDataMatchmaker.SetTeamSensitiveDataForUnhandledActors is called // TODO add hostile atsds and connect friendly/hostile ones to respective clients (Patch in ATSD.OnCheck/RebuildObservers) }
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 void SendNotification() { foreach (LobbyPlayerInfo playerInfo in TeamInfo.TeamPlayerInfo) { if (!playerInfo.IsNPCBot) { LobbyServerConnection player = LobbyServer.GetPlayerByAccountId(playerInfo.AccountId); LobbyTeamInfo teamInfoClone = TeamInfo.Clone(); foreach (LobbyPlayerInfo pi in teamInfoClone.TeamPlayerInfo) { if (pi.PlayerId == playerInfo.PlayerId) { pi.ControllingPlayerId = 0; } } LobbyPlayerInfo playerInfoClone = playerInfo.Clone(); playerInfoClone.ControllingPlayerId = 0; //Log.Print(LogType.Debug, $"Sending notification to {Players[i]}"); GameInfoNotification gameInfoNotification = new GameInfoNotification() { GameInfo = GameInfo, PlayerInfo = playerInfoClone, TeamInfo = teamInfoClone }; _ = player.SendMessage(gameInfoNotification); } } }
public void HandleEnterGame(C_EnterGame enterGamePacket) { if (ServerState != PlayerServerState.ServerStateLobby) { return; } LobbyPlayerInfo playerInfo = LobbyPlayers.Find(p => p.Name == enterGamePacket.Name); if (playerInfo == null) { return; } MyPlayer = ObjectManager.Instance.Add <Player>(); { MyPlayer.PlayerDbId = playerInfo.PlayerDbId; MyPlayer.Info.Name = playerInfo.Name; MyPlayer.Info.PosInfo.State = CreatureState.Idle; MyPlayer.Info.PosInfo.MoveDir = MoveDir.Down; MyPlayer.Info.PosInfo.PosX = 0; MyPlayer.Info.PosInfo.PosY = 0; MyPlayer.Stat.MergeFrom(playerInfo.StatInfo); MyPlayer.Session = this; S_ItemList itemListPacket = new S_ItemList(); // 아이템 목록을 갖고 온다 using (AppDbContext db = new AppDbContext()) { List <ItemDb> items = db.Items .Where(i => i.OwnerDbId == playerInfo.PlayerDbId) .ToList(); foreach (ItemDb itemDb in items) { Item item = Item.MakeItem(itemDb); if (item != null) { MyPlayer.Inven.Add(item); ItemInfo info = new ItemInfo(); info.MergeFrom(item.Info); itemListPacket.Items.Add(info); } } } Send(itemListPacket); } ServerState = PlayerServerState.ServerStateGame; GameLogic.Instance.Push(() => { GameRoom room = GameLogic.Instance.Find(1); room.Push(room.EnterGame, MyPlayer, true); }); }
public static LobbyPlayerInfo GetPlayerInfo(long accountId) { LobbyPlayerInfo playerInfo = null; ActivePlayers.TryGetValue(accountId, out playerInfo); return(playerInfo); }
public void CmdBroadcastPlayername(uint playerID) { LobbyPlayerInfo lpi = NetworkManagerV2.single.GetLobbyPlayer(playerID); if (lpi != null) { Debug.Log(playerName); RpcBroadcastPlayername(playerID, lpi.lobbyPlayer.playerName); } }
public void AddPlayer(int index, string name, Color color) { LobbyPlayerInfo info = playersInfo[index]; info.gameObject.SetActive(true); info.playerName.text = name; info.playerColor.color = color; playersPlaceholders[index].SetActive(false); SetColor(color, lobbySpaceship[index]); }
public void RemovePlayer(int index) { LobbyPlayerInfo info = playersInfo[index]; info.gameObject.SetActive(false); info.playerName.text = name; info.playerColor.color = Color.white; playersPlaceholders[index].SetActive(true); SetColor(Color.grey, lobbySpaceship[index]); }
public override GameObject OnLobbyServerCreateLobbyPlayer( NetworkConnection conn, short playerControllerId ) { LobbyPlayerInfo lobbyPlayerInfo = (LobbyPlayerInfo)Instantiate(this.lobbyPlayerPrefab); return(lobbyPlayerInfo.gameObject); }
protected override void OnClose(CloseEventArgs e) { LobbyPlayerInfo playerInfo = SessionManager.GetPlayerInfo(this.AccountId); if (playerInfo != null) { Log.Print(LogType.Lobby, string.Format(Config.Messages.PlayerDisconnected, this.UserName)); SessionManager.OnPlayerDisconnect(this); } }
public void UpdateLobbyData(LobbyPlayerInfo data) { var pl = LobbyPageVM.PlayersOnline.Where(d => d.Name == data.name).FirstOrDefault(); if (pl == null) { return; } pl.Name = data.name; pl.ExtraInfo = data.info; LobbyPageVM.PlayerOnlineCount = LobbyPageVM.PlayersOnline.Count; }
private void SpawnPlayerCharacter(LobbyPlayerInfo playerInfo) { //# Log.Print(LogType.Error, "SpawnPlayerCharacter " + playerInfo.CharacterInfo.CharacterType.ToString()); GamePlayer gamePlayer = GetGamePlayerByPlayerId(playerInfo.PlayerId); SpawnObject <ActorTeamSensitiveData>(MiscLoader, "ActorTeamSensitiveData_Friendly", out ActorTeamSensitiveData characterFriendly); SpawnObject(AssetsLoader, playerInfo.CharacterInfo.CharacterType.ToString(), out GameObject character); ActorData characterActorData = character.GetComponent <ActorData>(); characterActorData.SetClientFriendlyTeamSensitiveData(characterFriendly); characterActorData.ServerLastKnownPosSquare = Board.GetBoardSquare(5, 5); characterActorData.InitialMoveStartSquare = Board.GetBoardSquare(5, 5); characterActorData.UpdateDisplayName(playerInfo.Handle); characterActorData.PlayerIndex = playerInfo.PlayerId; //characterActorData.ActorIndex = playerInfo.PlayerId; PlayerData characterPlayerData = character.GetComponent <PlayerData>(); characterPlayerData.m_player = GameFlow.GetPlayerFromConnectionId(gamePlayer.Connection.connectionId); // TODO hardcoded connection id characterPlayerData.PlayerIndex = playerInfo.PlayerId; characterFriendly.SetActorIndex(characterActorData.ActorIndex); characterActorData.SetTeam(playerInfo.TeamId); GameFlowData.AddPlayer(character); var netChar = character.GetComponent <NetworkIdentity>(); var netAtsd = characterFriendly.GetComponent <NetworkIdentity>(); lock (GamePlayersByPlayerId) { foreach (GamePlayer player in GamePlayersByPlayerId.Values) { netChar.AddObserver(player.Connection); netAtsd.AddObserver(player.Connection); } } }
public void AddLobbyData(LobbyPlayerInfo data) { var pl = LobbyPageVM.PlayersOnline.Where(d => d.Name == data.name).FirstOrDefault(); if (pl != null) { return; } var pli = new LobbyPlayerVM() { Name = data.name, ExtraInfo = data.info }; LobbyPageVM.PlayersOnline.Add(pli); LobbyPageVM.PlayerOnlineCount = LobbyPageVM.PlayersOnline.Count; }
public void AddLobbyPlayer(LobbyPlayer lp) { for (int i = 0; i < lobbyPlayers.Count; i++) { if (lobbyPlayers[i].lobbyPlayer.netId == lp.netId) { return; } } LobbyPlayerInfo inf = new LobbyPlayerInfo(); inf.lobbyPlayer = lp; inf.UiIcon = NetworkManagerUI.single.AddLobbyPlayerUI(lp.playerName).GetComponent <LobbyPlayerUI>(); inf.UiIcon.Init(inf.lobbyPlayer.playerName); lobbyPlayers.Add(inf); StartCoroutine(DelayBroadcastPlayersName()); }
// 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); } }
public static LobbyPlayerInfo OnPlayerConnect(LobbyServerProtocol client, RegisterGameClientRequest clientRequest) { long sessionToken = GeneratedSessionToken++; Database.Account user = Database.Account.GetByUserName(clientRequest.AuthInfo.Handle); client.AccountId = user.AccountId; client.SessionToken = sessionToken; client.UserName = user.UserName; client.SelectedGameType = user.LastSelectedGameType; client.SelectedSubTypeMask = 0; LobbyPlayerInfo playerInfo = new LobbyPlayerInfo { AccountId = user.AccountId, BannerID = user.BannerID, BotCanTaunt = false, BotsMasqueradeAsHumans = false, CharacterInfo = CharacterManager.GetCharacterInfo(user.AccountId, user.LastCharacter), ControllingPlayerId = 0, EffectiveClientAccessLevel = ClientAccessLevel.Full, EmblemID = user.EmblemID, Handle = user.UserName, IsGameOwner = true, IsLoadTestBot = false, IsNPCBot = false, PlayerId = 0, ReadyState = ReadyState.Unknown, ReplacedWithBots = false, RibbonID = user.RibbonID, TitleID = user.TitleID, TitleLevel = 1 }; ActivePlayers.Add(user.AccountId, playerInfo); SessionTokenAccountIDCache.Add(sessionToken, playerInfo.AccountId); ActiveConnections.Add(user.AccountId, client); return(playerInfo); }
// 로그인 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); } }
private IEnumerator CheckRemovedPlayers() { yield return(new WaitForSeconds(1)); LobbyPlayerInfo toRemove = null; for (int i = 0; i < lobbyPlayers.Count; i++) { if (lobbyPlayers[i].lobbyPlayer == null) { if (lobbyPlayers[i].UiIcon.gameObject.activeInHierarchy) { Destroy(lobbyPlayers[i].UiIcon.gameObject); } toRemove = lobbyPlayers[i]; } } if (lobbyPlayers.Contains(toRemove)) { lobbyPlayers.Remove(toRemove); } }
public LobbyGameState(NetworkManager manager) { this.networkManager = manager; playersInLobby = new ListBox(); skin = GameObject.Find("__NetworkManager").GetComponent<NetworkManager>().InGamePregameStyle; racesList = new GUIContent[3]; racesList[0] = (new GUIContent("Fire")); racesList[1] = (new GUIContent("Ice")); racesList[2] = (new GUIContent("Lightning")); listStyle.normal.textColor = Color.white; listStyle.onHover.background = listStyle.hover.background = new Texture2D(2, 2); listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4; comboBoxControl = new ComboBox(new Rect(50, 100, 100, 20), racesList[0], racesList, "button", "box", listStyle); players = new LobbyPlayerInfo[6]; for (int i = 0; i < 6; ++i) { players[i] = new LobbyPlayerInfo(); } SetupPlayerInfo(0, 0); SetupPlayerInfo(0, 1); SetupPlayerInfo(0, 2); SetupPlayerInfo(1, 3); SetupPlayerInfo(1, 4); SetupPlayerInfo(1, 5); //add ourselves to the lobby and update everyone playersInLobby.AddEntry(networkManager.accountName); }
public LobbyGameState(NetworkManager manager) { this.networkManager = manager; playersInLobby = new ListBox(); skin = GameObject.Find("__NetworkManager").GetComponent <NetworkManager>().InGamePregameStyle; racesList = new GUIContent[3]; racesList[0] = (new GUIContent("Fire")); racesList[1] = (new GUIContent("Ice")); racesList[2] = (new GUIContent("Lightning")); listStyle.normal.textColor = Color.white; listStyle.onHover.background = listStyle.hover.background = new Texture2D(2, 2); listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4; comboBoxControl = new ComboBox(new Rect(50, 100, 100, 20), racesList[0], racesList, "button", "box", listStyle); players = new LobbyPlayerInfo[6]; for (int i = 0; i < 6; ++i) { players[i] = new LobbyPlayerInfo(); } SetupPlayerInfo(0, 0); SetupPlayerInfo(0, 1); SetupPlayerInfo(0, 2); SetupPlayerInfo(1, 3); SetupPlayerInfo(1, 4); SetupPlayerInfo(1, 5); //add ourselves to the lobby and update everyone playersInLobby.AddEntry(networkManager.accountName); }
public void HandleLogin(C_Login loginPacket) { // TODO 보안체크 더 강하게 if (ServerState != PlayerServerState.ServerStateLogin) { return; } // TODO 각종 상황에 대비 // -동시? // -악질 패킷 // -이상한 타이밍 LobbyPlayers.Clear(); using (AppDbContext db = new AppDbContext()) { AccountDb findAccount = db.Accounts .Include(a => a.Players) .Where(a => a.AccountName == loginPacket.UniqueId) .FirstOrDefault(); if (findAccount != null) { // 로그인 성공 AccountDbId = findAccount.AccountDbId; // Id는 자주쓰니 기억 S_Login loginOk = new S_Login() { LoginOk = 1 }; foreach (PlayerDb playerDb in findAccount.Players) { LobbyPlayerInfo lobbyPlayer = new LobbyPlayerInfo() { PlayerDbId = playerDb.PlayerDbId, Name = playerDb.PlayerName, StatInfo = new StatInfo() { Level = playerDb.Level, Hp = playerDb.Hp, MaxHp = playerDb.MaxHp, Attack = playerDb.Attack, Speed = playerDb.Speed, TotalExp = playerDb.TotalExp } }; // 메모리에 들고있는다 DB접근 최소화 LobbyPlayers.Add(lobbyPlayer); // 패킷을 넣어준다 loginOk.Players.Add(lobbyPlayer); } Send(loginOk); // 로비로 이동 ServerState = PlayerServerState.ServerStateLobby; } else { // 실패 // TEMP_ 새계정으로 AccountDb newAccount = new AccountDb() { AccountName = loginPacket.UniqueId }; db.Accounts.Add(newAccount); bool success = db.SaveChangesEx(); if (success == false) { return; } AccountDbId = newAccount.AccountDbId; // Id는 자주쓰니 기억 // 로그인 실패 S_Login loginOk = new S_Login() { LoginOk = 1 }; Send(loginOk); // 로비로 이동 ServerState = PlayerServerState.ServerStateLobby; } } }
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 void HandlePlayerInfoUpdateRequest(PlayerInfoUpdateRequest request) { LobbyPlayerInfoUpdate playerInfoUpdate = request.PlayerInfoUpdate; if (request.GameType != null && request.GameType.HasValue) { SetGameType(request.GameType.Value); } if (playerInfoUpdate.CharacterType != null && playerInfoUpdate.CharacterType.HasValue) { SetCharacterType(playerInfoUpdate.CharacterType.Value); LobbyPlayerInfo playerInfo = SessionManager.GetPlayerInfo(this.AccountId); PersistedAccountData accountData = AccountManager.GetPersistedAccountData(this.AccountId); // should be automatic when account gets its data from database, but for now we modify the needed things here accountData.AccountComponent.LastCharacter = playerInfo.CharacterInfo.CharacterType; accountData.AccountComponent.SelectedBackgroundBannerID = playerInfo.BannerID; accountData.AccountComponent.SelectedForegroundBannerID = playerInfo.EmblemID; accountData.AccountComponent.SelectedRibbonID = playerInfo.RibbonID; accountData.AccountComponent.SelectedTitleID = playerInfo.TitleID; // end "should be automatic" PlayerAccountDataUpdateNotification updateNotification = new PlayerAccountDataUpdateNotification() { AccountData = accountData }; Send(updateNotification); PlayerInfoUpdateResponse response = new PlayerInfoUpdateResponse() { PlayerInfo = playerInfo, CharacterInfo = playerInfo.CharacterInfo, OriginalPlayerInfoUpdate = request.PlayerInfoUpdate, ResponseId = request.RequestId }; Send(response); } if (playerInfoUpdate.AllyDifficulty != null && playerInfoUpdate.AllyDifficulty.HasValue) { SetAllyDifficulty(playerInfoUpdate.AllyDifficulty.Value); } if (playerInfoUpdate.CharacterAbilityVfxSwaps != null && playerInfoUpdate.CharacterAbilityVfxSwaps.HasValue) { SetCharacterAbilityVfxSwaps(playerInfoUpdate.CharacterAbilityVfxSwaps.Value); } if (playerInfoUpdate.CharacterCards != null && playerInfoUpdate.CharacterCards.HasValue) { SetCharacterCards(playerInfoUpdate.CharacterCards.Value); } if (playerInfoUpdate.CharacterLoadoutChanges != null && playerInfoUpdate.CharacterLoadoutChanges.HasValue) { SetCharacterLoadoutChanges(playerInfoUpdate.CharacterLoadoutChanges.Value); } if (playerInfoUpdate.CharacterMods != null && playerInfoUpdate.CharacterMods.HasValue) { SetCharacterMods(playerInfoUpdate.CharacterMods.Value); } if (playerInfoUpdate.CharacterSkin != null && playerInfoUpdate.CharacterSkin.HasValue) { SetCharacterSkin(playerInfoUpdate.CharacterSkin.Value); } if (playerInfoUpdate.ContextualReadyState != null && playerInfoUpdate.ContextualReadyState.HasValue) { SetContextualReadyState(playerInfoUpdate.ContextualReadyState.Value); } if (playerInfoUpdate.EnemyDifficulty != null && playerInfoUpdate.EnemyDifficulty.HasValue) { SetEnemyDifficulty(playerInfoUpdate.EnemyDifficulty.Value); } if (playerInfoUpdate.LastSelectedLoadout != null && playerInfoUpdate.LastSelectedLoadout.HasValue) { SetLastSelectedLoadout(playerInfoUpdate.LastSelectedLoadout.Value); } //Console.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); }
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { //UIConsole.Log ("OnServerAddPlayer " + Application.loadedLevelName); if (CheckIfLobbyScene ()) { base.OnServerAddPlayer (conn, playerControllerId); if(_lobbyInfo!=null) NetworkServer.Destroy(_lobbyInfo.gameObject); _lobbyInfo = ((GameObject)Instantiate(lobbyInfoPrefab)).GetComponent<LobbyPlayerInfo>(); NetworkServer.Spawn(_lobbyInfo.gameObject); } else { int num = 0; foreach (PlayerController current in conn.playerControllers) { if (current.IsValid) { num++; } } if (num > this.maxPlayersPerConnection) { UnityEngine.Networking.NetworkSystem.EmptyMessage msg = new UnityEngine.Networking.NetworkSystem.EmptyMessage (); conn.Send (45, msg); return; } if(resetSpawnPointsOnSceneChange) { GameObject.Find("RespawnManager").GetComponent<RespawnPointsManager>().SetupInitialSpawnPoints(); resetSpawnPointsOnSceneChange = false; } Vector3 spawnPos = GameObject.Find("RespawnManager").GetComponent<RespawnPointsManager>().GetInitialSpawnPoint(); //UIConsole.Log()); GameObject player = (GameObject)Object.Instantiate(onlinePlayerPrefab,spawnPos,Quaternion.identity); NetworkServer.AddPlayerForConnection(conn,player,playerControllerId); //UIConsole.Log("FAILED TO ADD PLAYER"); } }
public void HandleLogin(C_Login loginPacket) { // TODO : 이런 저런 보안 체크 if (ServerState != PlayerServerState.ServerStateLogin) { return; } // TODO : 문제가 있긴 있다 // - 동시에 다른 사람이 같은 UniqueId을 보낸다면? // - 악의적으로 여러번 보낸다면 // - 쌩뚱맞은 타이밍에 그냥 이 패킷을 보낸다면? LobbyPlayers.Clear(); using (AppDbContext db = new AppDbContext()) { AccountDb findAccount = db.Accounts .Include(a => a.Players) .Where(a => a.AccountName == loginPacket.UniqueId).FirstOrDefault(); if (findAccount != null) { // AccountDbId 메모리에 기억 AccountDbId = findAccount.AccountDbId; S_Login loginOk = new S_Login() { LoginOk = 1 }; foreach (PlayerDb playerDb in findAccount.Players) { LobbyPlayerInfo lobbyPlayer = new LobbyPlayerInfo() { PlayerDbId = playerDb.PlayerDbId, Name = playerDb.PlayerName, StatInfo = new StatInfo() { Level = playerDb.Level, Hp = playerDb.Hp, MaxHp = playerDb.MaxHp, Attack = playerDb.Attack, Speed = playerDb.Speed, TotalExp = playerDb.TotalExp } }; // 메모리에도 들고 있다 LobbyPlayers.Add(lobbyPlayer); // 패킷에 넣어준다 loginOk.Players.Add(lobbyPlayer); } Send(loginOk); // 로비로 이동 ServerState = PlayerServerState.ServerStateLobby; } else { AccountDb newAccount = new AccountDb() { AccountName = loginPacket.UniqueId }; db.Accounts.Add(newAccount); bool success = db.SaveChangesEx(); if (success == false) { return; } // AccountDbId 메모리에 기억 AccountDbId = newAccount.AccountDbId; S_Login loginOk = new S_Login() { LoginOk = 1 }; Send(loginOk); // 로비로 이동 ServerState = PlayerServerState.ServerStateLobby; } } }
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); } } }
public static void AddToQueue(GameType gameType, LobbyPlayerInfo playerInfo) { // TODO }
private bool FillTeam(Team team, TeamCompositionRules compositionRules, int maxPlayers, int maxBots, ref List <LobbyServerConnection> availablePlayers, ref LobbyTeamInfo teamInfo) { Log.Print(LogType.Debug, $"Filling Team {team.ToString()}"); int usedPlayers = 0; int usedBots = 0; List <LobbyPlayerInfo> playerInfo = new List <LobbyPlayerInfo>(); for (int slot = 1; slot <= 5; slot++) { //Log.Print(LogType.Debug, "fillteam:: slot "+slot); FreelancerSet botSet = new FreelancerSet() { Roles = new List <CharacterRole>(), Types = new List <CharacterType>() }; bool filled = false; if (usedPlayers != maxPlayers) { foreach (LobbyServerConnection player in availablePlayers) { bool matchedAny = false; bool matched = true; //Log.Print(LogType.Debug, "matching rules with " + player.UserName); foreach (TeamCompositionRules.SlotTypes slotType in compositionRules.Rules.Keys) { if (compositionRules.MatchesSlotType(slotType, team, slot)) { matchedAny = true; //Log.Print(LogType.Debug, "Matched slotType " + slotType.ToString()); /*if (!CharacterUtils.MatchesCharacter(player.PlayerInfo.GetCharacterType(), compositionRules.Rules[slotType])) * { * //Log.Print(LogType.Debug, "not matched rule"); * matched = false; * * if (usedBots == maxBots) * { * break; * } * else * { * FreelancerSet tempSet = compositionRules.Rules[slotType]; * if (tempSet.Roles != null) * botSet.Roles.AddRange(tempSet.Roles); * if (tempSet.Types != null) * botSet.Types.AddRange(tempSet.Types); * } * }*/ } } if (matchedAny && matched) { //Log.Print(LogType.Debug, "Adding player"); LobbyPlayerInfo info = player.GetLobbyPlayerInfo().Clone(); info.TeamId = team; playerInfo.Add(info); filled = true; usedPlayers++; availablePlayers.Remove(player); break; } } } if (!filled) { // try fill with bots if (usedBots != maxBots) // Bots remaining to fill { // create bot //Log.Print(LogType.Debug, "creating bot"); LobbyPlayerInfo botInfo = CharacterUtils.CreateBotCharacterFromFreelancerSet(botSet); botInfo.TeamId = team; playerInfo.Add(botInfo); usedBots++; } } } //Log.Print(LogType.Debug, "For finished"); if (usedPlayers != maxPlayers) { //Log.Print(LogType.Debug, "Bot overflow"); QueueInfo.QueueStatus = QueueStatus.QueueDoesntHaveEnoughHumans; return(false); } //Log.Print(LogType.Debug, "Filling team info"); foreach (LobbyPlayerInfo playerinfo in playerInfo) { teamInfo.TeamPlayerInfo.Add(playerinfo); } //Log.Print(LogType.Debug, "TeamFilled!"); return(true); }
private void InitializeGame(Scene scene) { GameManager.Get().SetTeamInfo(TeamInfo); GameManager.Get().SetGameInfo(GameInfo); SpawnObject("ApplicationSingletonsNetId"); var gameSceneSingletons = SpawnObject("GameSceneSingletons"); gameSceneSingletons.SetActive(true); //var cameraMan = gameSceneSingletons.GetComponent<CameraManager>(); //if (cameraMan != null) //{ // GameObject.Destroy(cameraMan); //} //else //{ // Log.Info("CameraManager is null"); //} var SharedEffectBarrierManager = SpawnObject("SharedEffectBarrierManager"); var SharedActionBufferObject = SpawnObject("SharedActionBuffer"); SharedActionBuffer = SharedActionBufferObject.GetComponent <SharedActionBuffer>(); SharedActionBuffer.Networkm_actionPhase = ActionBufferPhase.Done; foreach (GameObject sceneObject in scene.GetRootGameObjects()) { if (sceneObject.GetComponent <NetworkIdentity>() != null && !sceneObject.activeSelf) { Log.Info($"Activating scene object '{sceneObject.name}'"); sceneObject.SetActive(true); NetworkServer.Spawn(sceneObject); } } GameFlowData.Get().gameState = GameState.SpawningPlayers; bool destroyVisualsLoader = false; if (destroyVisualsLoader) { GameObject visualsLoader = GameObject.Find("VisualsLoader"); if (visualsLoader != null) { Log.Info("Trying to destroy VisualsLoader"); GameObject.Destroy(visualsLoader); } } Log.Info("Board is " + Board.Get()); List <LobbyPlayerInfo> playerInfoList = GameManager.Get().TeamInfo.TeamPlayerInfo; IsMapLoaded = true; for (int i = 0; i < playerInfoList.Count; i++) { LobbyPlayerInfo playerInfo = playerInfoList[i]; AddCharacterActor(playerInfo); } GameFlowData.Get().Networkm_currentTurn = 0; GameFlowData.Get().gameState = GameState.StartingGame; // Show what objects are present in the current scene UnityUtils.DumpSceneObjects(); WebsocketManager.ReportGameReady(); // Not sure where exactly it is supposed to happen }