Example #1
0
        protected override void OnConnected(TcpSession session)
        {
            var currentGameServerSession = _gameServerSessionsById[session.Id];

            //send map tiles to the connected client.
            currentGameServerSession.SendNullTerminated(CommandStringHelper.GetUpdateMapCommandStringFromTileMatrix(MapTileMatrix));

            //send the client's ID to the client.
            currentGameServerSession.SendNullTerminated(CommandStringHelper.GetClientIdCommandStringFromClientId(session.Id));

            //send a message to all other clients that a player has joined, and attach the player's initial position.
            MulticastNullTerminated(CommandStringHelper.GetPlayerUpdateCommandStringFromGameServerSession(currentGameServerSession));
        }
Example #2
0
        private void HandleReceivedCommand(string commandName, string[] commandArguments)
        {
            switch (commandName)
            {
            case "POSITIONUPDATE":
            {
                //parse the position X and Y coordinates from the command.
                var playerPosition = new PlayerPosition()
                {
                    X = double.Parse(commandArguments[0], Program.UnitedStatesCulture),
                    Y = double.Parse(commandArguments[1], Program.UnitedStatesCulture)
                };

                PlayerPosition = playerPosition;

                //broadcast a player update to all the server's clients.
                _server.MulticastNullTerminated(
                    CommandStringHelper.GetPlayerUpdateCommandStringFromGameServerSession(this));
                break;
            }
            }
        }