// 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 ); }
// 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(); }
internal static bool FirePlayerConnectedEvent( Session session ) { bool cancel = false; if( OnPlayerConnected != null ) OnPlayerConnected( session, ref cancel ); return !cancel; }
public static void RegisterSession( Session session ) { sessions.Add( session ); }
public void ProcessLogout( Session session ) { TotalTime += DateTime.UtcNow.Subtract( session.LoginTime ); LastSeen = DateTime.UtcNow; Online = false; PlayerObject = null; }
public void ProcessFailedLogin( Session session ) { LastFailedLoginDate = DateTime.UtcNow; LastFailedLoginIP = session.IP; Interlocked.Increment( ref FailedLoginCount ); }
internal static void RaiseSessionDisconnectedEvent( Session session, LeaveReason leaveReason ) { var h = SessionDisconnected; if( h != null ) h( null, new SessionDisconnectedEventArgs( session, leaveReason ) ); }
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; }
internal static void RaiseSessionConnectedEvent( Session session ) { var h = SessionConnected; if( h != null ) h( null, new SessionConnectedEventArgs( session ) ); }
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; }
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 ); } } }
internal static void UnregisterSession( Session session ) { if( session == null ) throw new ArgumentNullException( "session" ); lock( SessionLock ) { if( Sessions.Contains( session ) ) { Sessions.Remove( session ); } } }
// 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 ); } }
// 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(); }