コード例 #1
0
        public void Disconnect()
        {
            Debug.Log(tcp.socket.Client.RemoteEndPoint + " has diconnected");

            //This is done because this function is not called form the main thread so we need to make sure that the destroy of the object occurs in the main thread
            ThreadManager.ExecuteOnMainThread(() =>
            {
                UnityEngine.Object.Destroy(serverMasterController.gameObject);
                serverMasterController = null;
            });


            tcp.Disconnect();
            udp.Disconnect();

            ServerSend.PlayerDisconnected(id);
        }
コード例 #2
0
        public void SendIntoGame(string connectionID, string playerName)
        {
            Vector3 spawnPos = ServerSideGameManager.instance.spawnPositions[(count++) % ServerSideGameManager.instance.spawnPositions.Count];

            serverMasterController = ServerSideGameManager.instance.InstantiatePlayer((int)EnumData.Heroes.Medusa);
            serverMasterController.Initialise(id, connectionID, playerName, spawnPos);


            //This will send all other players information to our new player
            foreach (ServerSideClient client in Server.clients.Values)
            {
                if (client.serverMasterController != null)
                {
                    if (client.id != id)
                    {
                        ServerSend.SpawnPlayer(id, client.serverMasterController);
                    }
                }
            }


            //This will send new player information to all other players and themselves
            foreach (ServerSideClient client in Server.clients.Values)
            {
                if (client.serverMasterController != null)
                {
                    ServerSend.SpawnPlayer(client.id, serverMasterController);
                }
            }

            List <WorldGridItem> worldGridItemList = new List <WorldGridItem>();

            for (int i = 0; i < ServerSideGameManager.instance.toNetworkTileType.Count; i++)
            {
                List <Vector3Int> positionsOfTile = GridManager.instance.GetAllPositionForTileMap(ServerSideGameManager.instance.toNetworkTileType[i]);
                WorldGridItem     worldGridItem   = new WorldGridItem((int)ServerSideGameManager.instance.toNetworkTileType[i], positionsOfTile);
                worldGridItemList.Add(worldGridItem);
            }

            WorldUpdate worldUpdate = new WorldUpdate(ServerSideGameManager.instance.serverWorldSequenceNumber, worldGridItemList.ToArray(), new GameData((int)ServerSideGameManager.instance.currentGameState, ServerSideGameManager.instance.timeToStartMatch), ServerSideGameManager.projectilesDic, ServerSideGameManager.enemiesDic, ServerSideGameManager.animatingStaticTileDic, GridManager.instance.portalTracker.portalEntranceDic);

            ServerSend.SpawnGridWorld(id, worldUpdate);
        }
コード例 #3
0
        private void FixedUpdate()
        {
            serverWorldSequenceNumber++;

            DealItemSpawn();
            DealCereberausHeadRotation();
            DealWorldDestruction();
            DealMatchStartTime();
            //////Debug.Log("<color=blue>inputsequence </color>"+ playerMovingCommandSequenceNumber + "<color=blue>inputs </color> "+ inputs[0]+" "+inputs[1]+" "+inputs[2]+" "+inputs[3]);

            List <WorldGridItem> worldGridItemList = new List <WorldGridItem>();

            for (int i = 0; i < toNetworkTileType.Count; i++)
            {
                List <Vector3Int> positionsOfTile = GridManager.instance.GetAllPositionForTileMap(toNetworkTileType[i]);
                //Debug.LogError("TileType: " + toNetworkTileType[i] + " positionsOfTile " + positionsOfTile.Count);
                WorldGridItem worldGridItem = new WorldGridItem((int)toNetworkTileType[i], positionsOfTile);
                worldGridItemList.Add(worldGridItem);
            }


            GameData gameData = new GameData((int)currentGameState, timeToStartMatch);

            worldUpdatesToBeSentFromServerToClient.Add(new WorldUpdate(serverWorldSequenceNumber, worldGridItemList.ToArray(), gameData, new Dictionary <int, ProjectileData>(projectilesDic), new Dictionary <int, EnemyData>(enemiesDic), new Dictionary <int, AnimatingStaticTile>(animatingStaticTileDic), GridManager.instance.portalTracker.portalEntranceDic));

            //Local client sending data
            if (worldUpdatesToBeSentFromServerToClient.Count >= snapShotsInOnePacket)
            {
                if (previousHistoryForWorldUpdatesToBeSentToServerCollection.Count > packetHistorySize)
                {
                    previousHistoryForWorldUpdatesToBeSentToServerCollection.RemoveAt(0);
                }

                ServerSend.WorldUpdate(worldUpdatesToBeSentFromServerToClient, previousHistoryForWorldUpdatesToBeSentToServerCollection);

                previousHistoryForWorldUpdatesToBeSentToServerCollection.Add(new PreviousWorldUpdatePacks(worldUpdatesToBeSentFromServerToClient.ToArray()));

                worldUpdatesToBeSentFromServerToClient.Clear();

                //Debug.Log("<color=red>--------------------------------------------------------------------</color>");
            }
        }
コード例 #4
0
            public void Connect(TcpClient socket)
            {
                this.socket = socket;
                Debug.Log("Assigning socket here " + id);
                if (this.socket == null)
                {
                    Debug.LogError("Culprit " + id);
                }
                this.socket.ReceiveBufferSize = dataBufferSize;
                this.socket.SendBufferSize    = dataBufferSize;

                stream = this.socket.GetStream();

                receivedData = new Packet();

                receiveBuffer = new byte[dataBufferSize];

                //This enables to read data from client
                stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null);

                //Send welcome packet
                ServerSend.Welcome(id, "Welcome to the server!");
            }