Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        public void Login(string user)
        {
            var client = OperationContext.Current.GetCallbackChannel <IArenaCallback>();

            EventLog.WriteMessageToLog(strLogPath, "Client: " + user + " want to log in");

            if (!avatarDictionary.Values.ToList().Exists(c => c.Login.Equals(user)) && !_isGameStarted && avatarDictionary.Count <= 8)
            {
                if (_currentMap != null)
                {
                    if (_currentMap.StartingPositionList.Count < _numberOfLoggedRobots)
                    {
                        client.reciveInitialData(InitialServerResponse.Exception("Too many players, no place for you"));
                        EventLog.WriteMessageToLog(strLogPath, "ERROR: Client: " + user + " cannot log in because there are too many players");
                        return;
                    }
                }

                string color = "default";
                if (colorList.Count > 0)
                {
                    color = colorList.First();
                    colorList.Remove(color);
                }

                var robotAvatar = new RobotAvatar(user, color, null);
                PlayerLoginEvent(this, new PlayerLoginArgs(robotAvatar));
                Map mapForUser = null;

                avatarDictionary.Add(client, robotAvatar);
                _numberOfLoggedRobots++;
                OperationContext.Current.Channel.Faulted += new EventHandler(Channel_Faulted);
                OperationContext.Current.Channel.Closed  += new EventHandler(Channel_Faulted);

                if (_currentMap != null)
                {
                    if (_currentMap.StartingPositionNumber < _numberOfLoggedRobots)
                    {
                        client.reciveInitialData(InitialServerResponse.Exception("Too many players, no place for you"));
                        EventLog.WriteMessageToLog(strLogPath, "ERROR: Client: " + user + " cannot log in because there are too many players");

                        return;
                    }

                    robotAvatar.CurrentMapForRobot = CreateStartingPack(client, robotAvatar);
                    client.reciveInitialData(InitialServerResponse.PlayerRegistered(robotAvatar.Color, (int)_roundTime, robotAvatar.RobotPosition, new MapSize(_currentMap.MapWidth, _currentMap.MapHeight)));
                    EventLog.WriteMessageToLog(strLogPath, "Client: " + user + " logged in and recieved Color " + color + " and Starting Position: " + robotAvatar.RobotPosition.ToString());
                }
                else
                {
                    client.reciveInitialData(InitialServerResponse.Exception("Wait for map"));
                    EventLog.WriteMessageToLog(strLogPath, "Client: " + user + " has to wait for map");
                }
            }
            else if (avatarDictionary.Values.ToList().Exists(c => c.Login.Equals(user)))
            {
                client.reciveInitialData(InitialServerResponse.LoginAlreadyExists());
                EventLog.WriteMessageToLog(strLogPath, "ERROR: Login of Client: " + user + " already exists");
            }
            else if (_isGameStarted)
            {
                client.reciveInitialData(InitialServerResponse.Exception("Game already started, wait for the end!"));
                EventLog.WriteMessageToLog(strLogPath, "ERROR: Game Started!");
            }
            else
            {
                client.reciveInitialData(InitialServerResponse.Exception("Maximal number of players 9. Sorry no place for you!"));
                EventLog.WriteMessageToLog(strLogPath, "ERROR: Too many players");
            }
        }
Пример #2
0
 public InitialMessageRecivedArgs(InitialServerResponse response)
 {
     this.response = response;
 }