private Boolean TryAddToExistingGameSession(AddPlayerMessage addPlayerMessage) { var gotBusyGameSession = false; do { gotBusyGameSession = false; foreach (var gameSession in this.gameSessions.Values) { if (gameSession.GameSessionState == GameSession.GameSessionStates.AwaitingPlayer) { gameSession.AddPlayer(addPlayerMessage); return(true); } if (gameSession.GameSessionState == GameSession.GameSessionStates.AddingPlayer) { gotBusyGameSession = true; } } Thread.Sleep(50); } while (gotBusyGameSession); return(false); }
// This delay is mostly for the host player that loads too fast for the // server to have subscenes async loaded from OnStartServer ahead of it. IEnumerator OnServerAddPlayerDelayed(NetworkConnection conn, AddPlayerMessage msg) { // wait for server to async load all subscenes for game instances while (!subscenesLoaded) { yield return(null); } conn.Send(new SceneMessage { sceneName = gameScene, sceneOperation = SceneOperation.LoadAdditive }); base.OnServerAddPlayer(conn, msg); PlayerScore playerScore = conn.identity.GetComponent <PlayerScore>(); playerScore.playerNumber = clientIndex; playerScore.scoreIndex = clientIndex / subScenes.Count; playerScore.matchIndex = clientIndex % subScenes.Count; clientIndex++; if (subScenes.Count > 0) { SceneManager.MoveGameObjectToScene(conn.identity.gameObject, subScenes[clientIndex % subScenes.Count]); } }
protected void SetupLoginHandler() { // The client sends AddPlayer and then LoginRequest, instead we'll use the session token to determine // which Game the connection is fore AddPlayerMessage addPlayerMessage = null; Serializer.RegisterHandler(37, msg => { addPlayerMessage = (AddPlayerMessage)msg; }); Serializer.RegisterHandler(51, msg => { var loginReq = (LoginRequest)msg; if (addPlayerMessage == null) { Log.Print(LogType.Error, "Received LoginRequest before AddPlayerMessage!"); Disconnect(); return; } var gameManager = GameManagerHolder.FindGameManager(loginReq); if (gameManager == null) { Log.Print(LogType.Error, $"Didn't find a GameManager for {loginReq}'"); Disconnect(); return; } Send(52, new LoginResponse { Reconnecting = false, Success = true }); gameManager.AddPlayer(this, loginReq, addPlayerMessage); }); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { base.OnServerAddPlayer(conn, extraMessage); playersInServer++; //aumenta o numero de jogadores conectados turnMngr.AddPlayer(conn.playerController.gameObject); //passa a referencia do jogador para o TurnManager conn.playerController.gameObject.GetComponent <PlayerBHV>().playerID = playersInServer; //Seta o ID do player }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { //Debug.Log("OnServerAddPlayer: Adding new player"); // find empty player slot for (int slot = 0; slot < maxPlayers; slot++) { //Debug.Log("Checking slot: " + slot.ToString()); if (playerSlots[slot] == null) { var playerObj = (GameObject)GameObject.Instantiate(playerPrefab, Vector3.zero, Quaternion.identity); //Debug.Log("Starting new player in slot " + slot.ToString()); //playerObj.GetComponent<PlayerConnectionObj>().Start(); var player = playerObj.GetComponent <PlayerConnectionObj>(); Debug.Log("Server adding player. ID: " + slot.ToString()); player.playerId = slot; player.enemyId = (slot + 1) % maxPlayers; playerSlots[slot] = player; NetworkServer.AddPlayerForConnection(conn, playerObj); currentPlayers++; if (currentPlayers == maxPlayers) { logicCore.StartGameProcess(); } return; } //Debug.Log("Slot " + slot.ToString() + " not null"); } conn.Disconnect(); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { if (SceneManager.GetActiveScene().name != LobbyScene) { return; } if (lobbySlots.Count == maxConnections) { return; } allPlayersReady = false; if (LogFilter.Debug) { Debug.LogFormat("NetworkLobbyManager.OnServerAddPlayer playerPrefab:{0}", lobbyPlayerPrefab.name); } GameObject newLobbyGameObject = OnLobbyServerCreateLobbyPlayer(conn); if (newLobbyGameObject == null) { newLobbyGameObject = (GameObject)Instantiate(lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity); } var newLobbyPlayer = newLobbyGameObject.GetComponent <NobleMirrorLobbyPlayer>(); lobbySlots.Add(newLobbyPlayer); RecalculateLobbyPlayerIndices(); NetworkServer.AddPlayerForConnection(conn, newLobbyGameObject); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { if (LogFilter.Debug) { Debug.Log("NetworkManager.OnServerAddPlayer"); } if (playerPrefab == null) { Debug.LogError("The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object."); return; } if (playerPrefab.GetComponent <NetworkIdentity>() == null) { Debug.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab."); return; } if (playerPawnPrefab == null) { Debug.LogError("The PlayerClientPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object."); return; } if (playerPawnPrefab.GetComponent <NetworkIdentity>() == null) { Debug.LogError("The PlayerClientPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab."); return; } if (conn.playerController != null) { Debug.LogError("There is already a player for this connections."); return; } Transform startPos = GetStartPosition(); GameObject player = startPos != null ? Instantiate(playerPrefab, startPos.position, startPos.rotation) : Instantiate(playerPrefab); GameObject playerPawn = startPos != null ? Instantiate(playerPawnPrefab, startPos.position, startPos.rotation) : Instantiate(playerPawnPrefab); NetworkServer.AddPlayerForConnection(conn, player); NetworkServer.SpawnWithClientAuthority(playerPawn, conn); player.GetComponent <Client>().SetupPawn(playerPawn.GetComponent <NetworkIdentity>()); // spawn ball if two players if (numPlayers == 1) { ActiveBeerCrate = Instantiate(BeerCratePrefab, crateSpawn.position, crateSpawn.rotation); NetworkServer.Spawn(ActiveBeerCrate); } else if (numPlayers > 1 && !ActiveBeerCrate) { ActiveBeerCrate = Instantiate(BeerCratePrefab, crateSpawn.position, crateSpawn.rotation); NetworkServer.Spawn(ActiveBeerCrate); } }
protected void SetupLoginHandler() { // The client sends AddPlayer and then LoginRequest, instead we'll use the SessionToken to determine // which Game the connection is for AddPlayerMessage addPlayerMessage = null; Serializer.RegisterHandler(37, msg => { addPlayerMessage = (AddPlayerMessage)msg; }); Serializer.RegisterHandler((short)MyMsgType.LoginRequest, msg => { var loginReq = (LoginRequest)msg; SessionToken = Convert.ToInt64(loginReq.SessionToken); //PlayerInfo = SessionManager.Get(SessionToken); PlayerId = loginReq.PlayerId; GameManagerHolder.AssignServer(this); // Send login ok response Send((short)MyMsgType.LoginResponse, new LoginResponse { Reconnecting = false, Success = true }); }); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { if (LogFilter.Debug) { Debug.Log("NetworkManager.OnServerAddPlayer"); } if (playerPrefab == null) { Debug.LogError("The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object."); return; } if (playerPrefab.GetComponent <NetworkIdentity>() == null) { Debug.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab."); return; } if (conn.playerController != null) { Debug.LogError("There is already a player for this connections."); return; } //change the below to pick a prefab to spawn in Transform startPos = GetStartPosition(); GameObject player = startPos != null ? Instantiate(playerPrefab, startPos.position, startPos.rotation) : Instantiate(playerPrefab); NetworkServer.AddPlayerForConnection(conn, player); }
//public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { Debug.Log("adding player"); var player = (GameObject)GameObject.Instantiate(playerPrefab); //NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); NetworkServer.AddPlayerForConnection(conn, player); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { GameObject player = Instantiate(playerPrefab); NetworkServer.AddPlayerForConnection(conn, player); conn.playerController.GetComponent <NetworkPlayerRooms>().onPlayerReady.AddListener(CheckForPairs); }
private void AddToNewGameSession(AddPlayerMessage addPlayerMessage, CancellationToken cancellationToken) { var gameSessionToken = this.gameSessionTokenFactory.CreateGameSessionToken(); var gameSession = new GameSession(this.gameManagerFactory.Create(), this.maximumPlayerCount, this.playerCardRepository, gameSessionToken, cancellationToken, this.loggerFactory); gameSession.Start(); gameSession.AddPlayer(addPlayerMessage); this.gameSessions.Add(gameSessionToken, gameSession); }
// Note: if there are n players, numPlayers is n-1, ex. if there is 1 player, numPlayers is 0 public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { // Debug.Log("numPlayers connected to server: "+numPlayers); GameObject player = Instantiate(playerPrefab); playerID += 1; player.GetComponent <PlayerController>().playerName = "Player" + playerID; NetworkServer.AddPlayerForConnection(conn, player); }
void OnServerAddPlayerInternal(INetworkConnection conn, AddPlayerMessage msg) { logger.Log("PlayerSpawner.OnServerAddPlayer"); if (conn.Identity != null) { throw new InvalidOperationException("There is already a player for this connection."); } OnServerAddPlayer(conn); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage message) { base.OnServerAddPlayer(conn, message); if (Data == null) { Data = Instantiate(spawnPrefabs[0]).GetOrAddComponent <CGSNetData>(); NetworkServer.Spawn(Data.gameObject); } Data.RegisterScore(conn.playerController.gameObject, CardGameManager.Current.GameStartPointsCount); playController.netText.text = PlayerCountMessage + NetworkServer.connections.Count.ToString(); }
public void UnpackWrongMessage() { var message = new ReadyMessage(); byte[] data = MessagePacker.Pack(message); Assert.Throws <FormatException>(() => { AddPlayerMessage unpacked = MessagePacker.Unpack <AddPlayerMessage>(data); }); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage msg) { Debug.Assert(startPositions.Count == 2, "Pong Scene should have 2 start Poitions"); // add player at correct spawn position Transform startPos = numPlayers == 0 ? startPositions[0] : startPositions[1]; GameObject player = startPos != null ? Instantiate(playerPrefab, startPos.position, startPos.rotation) : Instantiate(playerPrefab); NetworkServer.AddPlayerForConnection(conn, player); }
public void AddPlayer(ClientConnection connection, LoginRequest loginReq, AddPlayerMessage msg) { _players.Add(loginReq.PlayerId, new GamePlayer(connection, loginReq, msg)); connection.ActiveGame = this; var gfPlayer = GameFlow.GetPlayerFromConnectionId(connection.connectionId); gfPlayer.m_id = (byte)loginReq.PlayerId; gfPlayer.m_valid = true; gfPlayer.m_accountId = long.Parse(loginReq.AccountId); gfPlayer.m_connectionId = connection.connectionId; GameFlow.playerDetails[gfPlayer] = new PlayerDetails(PlayerGameAccountType.Human) { m_team = Team.TeamA, m_handle = "test handle", m_accountId = gfPlayer.m_accountId, m_lobbyPlayerInfoId = 0 }; // This isn't actually correct, but the client logs a warning with what it expected and continues connection.Send(14, new CRCMessage { scripts = new[] { new CRCMessageEntry("ActorData", 0), new CRCMessageEntry("BrushCoordinator", 0), new CRCMessageEntry("ActorController", 0), new CRCMessageEntry("AbilityData", 0), new CRCMessageEntry("ActorStats", 0), new CRCMessageEntry("ActorStatus", 0), new CRCMessageEntry("ActorBehavior", 0), new CRCMessageEntry("PlayerData", 0), new CRCMessageEntry("PowerUp", 0), new CRCMessageEntry("GameFlow", 0), new CRCMessageEntry("TeamStatusDisplay", 0), new CRCMessageEntry("BarrierManager", 0), new CRCMessageEntry("GameFlowData", 0), new CRCMessageEntry("ObjectivePoints", 0), new CRCMessageEntry("CoinCarnageManager", 0), new CRCMessageEntry("ActorTeamSensitiveData", 0), new CRCMessageEntry("ActorAdditionalVisionProviders", 0), new CRCMessageEntry("ActorCinematicRequests", 0), new CRCMessageEntry("FreelancerStats", 0), new CRCMessageEntry("Manta_SyncComponent", 0), new CRCMessageEntry("Rampart_SyncComponent", 0), new CRCMessageEntry("SinglePlayerManager", 0) } }); connection.RegisterHandler <AssetsLoadingProgress>(61, _players[loginReq.PlayerId], OnAssetLoadingProgress); connection.RegisterHandler <AssetsLoadedNotification>(53, _players[loginReq.PlayerId], OnAssetsLoadedNotification); }
private void ProcessAddPlayerMessage(AddPlayerMessage addPlayerMessage) { if (this.AddPlayer(addPlayerMessage.Client, addPlayerMessage.Username)) { this.GameSessionState = GameSessionStates.Full; this.SendConfirmGameSessionReadyToLaunchMessage(); } else { this.GameSessionState = GameSessionStates.AwaitingPlayer; } }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { Player player = Instantiate(playerPrefab, battleField.GetRandomPositionFree2Walk, playerPrefab.transform.rotation).GetComponent <Player>(); if (NetworkServer.AddPlayerForConnection(conn, player.gameObject)) { player.OnDead += (x) => { player.RpcRespawnPlayer(x.netIdentity, battleField.GetRandomPositionFree2Walk); }; players.Add(player); } }
// AddPlayer handler for the server side public void OnAddPlayerServer(NetworkMessage netMsg) { m_connectionId++; AddPlayerMessage msg = netMsg.ReadMessage <AddPlayerMessage>(); GameObject newPlayer = SpawnManager.instance.InstantiatePool("Player", Vector3.zero, Quaternion.identity); NetworkServer.AddPlayerForConnection(netMsg.conn, newPlayer, msg.playerControllerId); MobaPlayer mobaPlayer = newPlayer.GetComponent <MobaPlayer>(); mobaPlayer.PlayerName = "Player " + m_connectionId; mobaPlayer.PickSlot = (MenuManager.instance.CurrentMenu as MenuPickSelection).AssignPlayerToFreeSlot(mobaPlayer); m_connectedPlayers.Add(netMsg.conn.connectionId, mobaPlayer); Debug.Log("------------Player Joined with IP------------ " + netMsg.conn.address); }
internal void Deserialize(byte[] data, AddPlayerMessage expected) { var message = AddPlayerMessageSerializer.Default.Deserialize(data); message.PacketType.Should().Be(expected.PacketType); message.Dpnid.Should().Be(expected.Dpnid); message.DpnidOwner.Should().Be(expected.DpnidOwner); message.Flags.Should().Be(expected.Flags); message.Version.Should().Be(expected.Version); message.VersionNotUsed.Should().Be(expected.VersionNotUsed); message.DnetClientVersion.Should().Be(expected.DnetClientVersion); message.Url.Should().Be(expected.Url); message.Data.Should().Equal(expected.Data); message.Name.Should().Be(expected.Name); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage msg) { // add player at correct spawn position Transform start = numPlayers == 0 ? leftRacketSpawn : rightRacketSpawn; GameObject player = Instantiate(playerPrefab, start.position, start.rotation); NetworkServer.AddPlayerForConnection(conn, player); // spawn ball if two players if (numPlayers == 2) { ball = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "Ball")); NetworkServer.Spawn(ball); } }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { // add player at correct spawn position Transform start = numPlayers == 0 ? leftRacketSpawn : rightRacketSpawn; GameObject player = Instantiate(playerPrefab, start.position, start.rotation); NetworkServer.AddPlayerForConnection(conn, player); // spawn ball if two players if (numPlayers == 2) { _ball = Instantiate(ballPrefab); NetworkServer.Spawn(_ball); } }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { GameObject player; Transform startPos = GetStartPosition(); if (startPos != null) { player = Instantiate(characters[chosenCharacter], startPos.position, startPos.rotation) as GameObject; } else { player = Instantiate(characters[chosenCharacter], Vector3.zero, Quaternion.identity) as GameObject; } NetworkServer.AddPlayerForConnection(conn, player); }
// called after the client calls ClientScene.AddPlayer with a msg parameter public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage message) { //print("OnServerAddPlayer"); // only while in lobby (aka after handshake and not ingame) if (lobby.ContainsKey(conn)) { // valid message bytes for index? if (message.value != null && message.value.Length == sizeof(int)) { // read the index and find the n-th character // (only if we know that he is not ingame, otherwise lobby has // no netMsg.conn key) int index = BitConverter.ToInt32(message.value, 0); string account = lobby[conn]; List <string> characters = Database.singleton.CharactersForAccount(account); // validate index if (0 <= index && index < characters.Count) { print(account + " selected player " + characters[index]); // load character data GameObject go = Database.singleton.CharacterLoad(characters[index], GetPlayerClasses(), false); // add to client NetworkServer.AddPlayerForConnection(conn, go); // addon system hooks Utils.InvokeMany(typeof(NetworkManagerMMO), this, "OnServerAddPlayer_", account, go, conn, message); // remove from lobby lobby.Remove(conn); } else { print("invalid character index: " + account + " " + index); ServerSendError(conn, "invalid character index", false); } } } else { print("AddPlayer: not in lobby" + conn); ServerSendError(conn, "AddPlayer: not in lobby", true); } }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage msg) { // add player at correct spawn position // Transform start = numPlayers == 0 ? leftRacketSpawn : rightRacketSpawn; // GameObject player = Instantiate(playerPrefab, start.position, start.rotation); GameObject player; if (!msg.webGL && GameObject.Find("yumiNetwork(Clone)") == null) { player = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "yumiNetwork")); } else { player = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "male")); } NetworkServer.AddPlayerForConnection(conn, player); GameObject.Find("server2client").GetComponent <Server2Client>().player = player; }
private void OnServerAddPlayer(NetworkConnection connection, AddPlayerMessage extraMessage, System.Action baseMethodCallback) // called when client call add player //UIDMessage message = MessagePacker.Unpack<UIDMessage>(extraMessage.value); //Debug.Log(message.uid); //EdDatabase.GetPlayerData(connection.connectionId, message.uid, match => { // if (match) { // baseMethodCallback.Invoke(); // } else { // connection.Disconnect(); // } //} { baseMethodCallback.Invoke(); PlayerController playerController = connection.playerController.gameObject.GetComponent <PlayerController>(); if (playerController) { int assignedSlot = GameController.Instance.AssignPlayerSlot(playerController); if (assignedSlot >= 0) { for (uint i = 0; i < GameController.Instance.bases[0].transform.childCount; ++i) { GameObject newPawn = Instantiate(GameController.Instance.pawnPrefab); newPawn.GetComponent <PawnController>().sphereMaterial = assignedSlot; // pick color here NetworkServer.SpawnWithClientAuthority(newPawn, connection); playerController.pawns.Add(newPawn.GetComponent <PawnController>()); } playerController.AssignSlot(assignedSlot); //if (GameController.Instance.AllSlotsFilled()) { // GameController.Instance.StartGame(); //} } else { connection.Disconnect(); } } }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { float x = UnityEngine.Random.Range(-spawnVolume.x / 2, spawnVolume.x / 2); float y = UnityEngine.Random.Range(-spawnVolume.y / 2, spawnVolume.y / 2); float z = UnityEngine.Random.Range(-spawnVolume.z / 2, spawnVolume.z / 2); Vector3 pos = new Vector3(x, y, z); GameObject player = Instantiate(playerPrefab, pos, Quaternion.identity); player.GetComponent <SphereCollider>().enabled = customObservers; player.GetComponent <AreaOfInterest>().customObservers = customObservers; NetworkServer.AddPlayerForConnection(conn, player); Stats.stats.Add(conn, new ClientStats()); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("OnServerAddPlayer ID: {0:0000} Observers: {1:0000} Pos: {2}", conn.connectionId, conn.playerController.observers.Count, conn.playerController.gameObject.transform.position); Console.ResetColor(); }
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage) { var freeMapID = NetworkGameManager.GetFreeMapID(); // var maxPlayers = FPClient.Instance != null ? FPClient.Instance.Lobby.NumMembers : 4; // var currentPlayers = NetworkServer.connections.Count; // if (currentPlayers > maxPlayers) // { // conn.Disconnect(); // return; // } var playerGO = Instantiate(playerPrefab); var player = playerGO.GetComponent <NetworkPlayer>(); player.MapID = freeMapID; NetworkServer.AddPlayerForConnection(conn, playerGO); }