Ejemplo n.º 1
0
 // Normal constructor
 internal Player( World _world, string _name, Session _session, Position _pos ) {
     world = _world;
     name = _name;
     nick = name;
     session = _session;
     pos = _pos;
     info = world.db.FindPlayerInfo( this );
 }
Ejemplo n.º 2
0
 // Normal constructor
 internal Player( World world, string name, Session session, Position position ) {
     if( name == null ) throw new ArgumentNullException( "name" );
     if( session == null ) throw new ArgumentNullException( "session" );
     World = world;
     Session = session;
     Position = position;
     Info = PlayerDB.FindOrCreateInfoForPlayer( name, session.IP );
     spamBlockLog = new Queue<DateTime>( Info.Rank.AntiGriefBlocks );
     ResetAllBinds();
 }
Ejemplo n.º 3
0
 internal static bool FirePlayerConnectedEvent( Session session )
 {
     bool cancel = false;
     if( OnPlayerConnected != null ) OnPlayerConnected( session, ref cancel );
     return !cancel;
 }
Ejemplo n.º 4
0
 public static void RegisterSession( Session session ) {
     sessions.Add( session );
 }
Ejemplo n.º 5
0
 public void ProcessLogout( Session session ) {
     TotalTime += DateTime.UtcNow.Subtract( session.LoginTime );
     LastSeen = DateTime.UtcNow;
     Online = false;
     PlayerObject = null;
 }
Ejemplo n.º 6
0
 public void ProcessFailedLogin( Session session ) {
     LastFailedLoginDate = DateTime.UtcNow;
     LastFailedLoginIP = session.IP;
     Interlocked.Increment( ref FailedLoginCount );
 }
Ejemplo n.º 7
0
 internal static void RaiseSessionDisconnectedEvent( Session session, LeaveReason leaveReason ) {
     var h = SessionDisconnected;
     if( h != null ) h( null, new SessionDisconnectedEventArgs( session, leaveReason ) );
 }
Ejemplo n.º 8
0
        public static bool RegisterPlayerAndCheckIfFull( Session session ) {
            if( session == null ) throw new ArgumentNullException( "session" );

            Player player = session.Player;

            // Kick other sessions with same player name
            List<Session> sessionsToKick = new List<Session>();
            lock( SessionLock ) {
                foreach( Session s in Sessions ) {
                    if( s == session ) continue;
                    if( s.Player.Name.Equals( player.Name, StringComparison.OrdinalIgnoreCase ) ) {
                        sessionsToKick.Add( s );
                        s.Kick( "Connected from elsewhere!", LeaveReason.ClientReconnect );
                        Logger.Log( "Session.LoginSequence: Player {0} logged in. Ghost was kicked.", LogType.SuspiciousActivity,
                                    s.Player.Name );
                    }
                }
            }

            // Wait for other sessions to exit/unregister (if any)
            foreach( Session ses in sessionsToKick ) {
                ses.WaitForDisconnect();
            }

            // Add player to the list
            lock( PlayerListLock ) {
                if( Players.Count >= ConfigKey.MaxPlayers.GetInt() && !player.Info.Rank.ReservedSlot ) {
                    return false;
                }
                Players.Add( player.Name, player );
                UpdatePlayerList();
                RaiseEvent( PlayerListChanged );
                session.IsRegistered = true;
            }
            return true;
        }
Ejemplo n.º 9
0
 internal static void RaiseSessionConnectedEvent( Session session ) {
     var h = SessionConnected;
     if( h != null ) h( null, new SessionConnectedEventArgs( session ) );
 }
Ejemplo n.º 10
0
 internal static bool RegisterSessionAndCheckConnectionCount( Session session ) {
     int maxSessions = ConfigKey.MaxConnectionsPerIP.GetInt();
     lock( SessionLock ) {
         if( maxSessions > 0 ) {
             int sessionCount = 0;
             foreach( Session s in Sessions ) {
                 if( s.IP.Equals( session.IP) ) {
                     sessionCount++;
                     if( sessionCount >= maxSessions ) {
                         return false;
                     }
                 }
             }
         }
         Sessions.Add( session );
     }
     return true;
 }
Ejemplo n.º 11
0
 static void CheckConnections( SchedulerTask param ) {
     TcpListener listenerCache = listener;
     if( listenerCache != null && listenerCache.Pending() ) {
         try {
             Session newSession = new Session( listenerCache.AcceptTcpClient() );
             newSession.Start();
         } catch( Exception ex ) {
             Logger.Log( "Server.CheckConnections: Could not accept incoming connection: " + ex, LogType.Error );
         }
     }
 }
Ejemplo n.º 12
0
 internal static void UnregisterSession( Session session ) {
     if( session == null ) throw new ArgumentNullException( "session" );
     lock( SessionLock ) {
         if( Sessions.Contains( session ) ) {
             Sessions.Remove( session );
         }
     }
 }
Ejemplo n.º 13
0
        // Remove player from the list, and notify remaining players
        public static void UnregisterPlayer( Session session ) {
            if( session == null ) throw new ArgumentNullException( "session" );

            Player player = session.Player;
            player.IsDisconnected = true;
            lock( PlayerListLock ) {
                if( !session.IsRegistered ) return;
                player.Info.ProcessLogout( session );

                Logger.Log( "{0} left the server.", LogType.UserActivity,
                            player.Name );
                if( session.IsReady && ConfigKey.ShowConnectionMessages.GetBool() ) {
                    SendToSeeing( String.Format( "&SPlayer {0}&S left the server.", player.GetClassyName() ), player );
                }

                if( player.World != null ) {
                    player.World.ReleasePlayer( player );
                }
                Players.Remove( player.Name );
                UpdatePlayerList();
                RaiseEvent( PlayerListChanged );
            }
        }
Ejemplo n.º 14
0
 // Check for player joins and send a message to the channels to notify
 public static void SendPlayerJoinMsg( Session session, ref bool cancel )
 {
     session.player.Message( "This server's IRC Bot is" + Color.Red + " Online." );
     session.player.Message( "Use '#<message>' in chat to forward messages to the IRC Channel(s)." );
     IRCMessage newMsg = new IRCMessage() { chatMessage = session.player.GetLogName() + " has joined " + Config.GetString( ConfigKey.ServerName ) + ".", destination = Destination.Channels };
     outMessages.Add( newMsg );
     IRCComm.Process();
 }