コード例 #1
0
ファイル: Zone.cs プロジェクト: klyed/Infantry-Online-Server
        /// <summary>
        /// Indicates that a player has joined the zone server
        /// </summary>
        public bool newPlayer(int id, string alias, Data.DB.player dbplayer)
        {
            if (string.IsNullOrWhiteSpace(alias))
            {
                Log.write(TLog.Error, "Zone.newPlayer(): Called with no alias.");
                return(false);
            }
            if (id == 0)
            {
                Log.write(TLog.Error, "Zone.newPlayer(): ID was 0 for player '{0}.", alias);
            }
            if (dbplayer == null)
            {
                Log.write(TLog.Error, "Zone.getPlayer(): Called with null dbplayer for '{0}'.", alias);
                return(false);
            }

            Player player = new Player();

            player.acctid     = dbplayer.alias1.account1.id;
            player.aliasid    = dbplayer.alias1.id;
            player.IPAddress  = dbplayer.alias1.IPAddress;
            player.dbid       = dbplayer.id;
            player.alias      = alias;
            player.permission = dbplayer.permission;
            player.zone       = this;
            player.arena      = "";
            player.chats      = new List <string>();

            // Add them to the Zone players list
            try
            {
                _players.Add(id, player);
            }
            catch
            {
                Log.write(TLog.Error, "Zone.newPlayer(): Key '{0}' already exists for player '{1}'.", id, alias);
                return(false);
            }

            // And the global list
            if (!_server.newPlayer(player))
            {
                // Back out of the zone list
                _players.Remove(id);

                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: Zone.cs プロジェクト: mizzouse/FreeInfantry
        /// <summary>
        /// Indicates that a player has joined the zone server
        /// </summary>
        public bool newPlayer(int id, string alias, Data.DB.player dbplayer)
        {
            if (string.IsNullOrWhiteSpace(alias))
            {
                Log.write(TLog.Error, "Zone.newPlayer(): Called with no alias.");
                return(false);
            }
            if (id == 0)
            {
                Log.write(TLog.Error, "Zone.newPlayer(): ID was 0 for player '{0}.", alias);
            }
            if (dbplayer == null)
            {
                Log.write(TLog.Error, "Zone.getPlayer(): Called with null dbplayer for '{0}'.", alias);
                return(false);
            }

            Player player = new Player();

            player.acctid     = dbplayer.alias1.account1.id;
            player.aliasid    = dbplayer.alias1.id;
            player.IPAddress  = dbplayer.alias1.IPAddress;
            player.dbid       = dbplayer.id;
            player.alias      = alias;
            player.permission = dbplayer.permission;
            player.zone       = this;
            player.arena      = "";
            player.chats      = new List <string>();

            // Add them to the Zone players list
            try
            {
                _players.Add(id, player);
            }
            catch
            {
                Log.write(TLog.Error, "Zone.newPlayer(): Key '{0}' already exists for player '{1}'.", id, alias);
                return(false);
            }

            // And the global list
            if (!_server.newPlayer(player))
            {
                // Back out of the zone list
                _players.Remove(id);

                return(false);
            }

            // Squad shit
            using (Data.InfantryDataContext db = _server.getContext())
            {
                Data.DB.squad pSquad = db.squads.FirstOrDefault(s => s.id == dbplayer.squad);

                //Is he in a squad?
                if (pSquad != null)
                {
                    //Check for any scheduled matches this squad may have
                    IQueryable <Data.DB.squadmatch> matches = db.squadmatches.Where
                                                                  (m => m.squad1 == pSquad.id || m.squad2 == pSquad.id);


                    if (matches.Count() > 0)
                    {
                        foreach (Data.DB.squadmatch match in matches)
                        {
                            Data.DB.squad squad1 = db.squads.FirstOrDefault(s => s.id == match.squad1);
                            Data.DB.squad squad2 = db.squads.FirstOrDefault(s => s.id == match.squad2);
                            _server.sendMessage(this, alias, string.Format("Your squad has a scheduled match at {0} ({1} vs {2})",
                                                                           match.dateBegin.ToString(), squad1.name, squad2.name));
                        }
                    }
                }
            }

            return(true);
        }