예제 #1
0
        /// <summary>
        /// Adds a socket connection to be tracked by the server
        /// </summary>
        public static bool TrackUserSocket(INetworkConnection client, ref string msg)
        {
            msg = "";
            if (client == null || client.RemoteEndPoint == null)
            {
                return(false);
            }

            if (Clients.ContainsKey(client.RemoteEndPoint as IPEndPoint))
            {
                Clients[client.RemoteEndPoint as IPEndPoint].KillConnection("New connection being made from elsewhere...");
                RemoveConnection(client.RemoteEndPoint as IPEndPoint);
            }

            InboundConnection inb = client as InboundConnection;

            if (inb != null && Clients.Count + 1 > inb.MyServer.MaxInboundConnections)
            {
                msg = "Server is full.";
                return(false);
            }

            Clients.Add(client.UID, client);
            Clients.Associate(client.RemoteEndPoint as IPEndPoint, client.UID);
            PerfMon.IncrementCustomCounter("Live Connections", 1);
            return(true);
        }
예제 #2
0
        public static bool RemoveConnection(Guid conId)
        {
            INetworkConnection con = null;

            if (!Clients.TryGetValue(conId, out con))
            {
                return(false);
            }

            if (con == null)
            {
                return(false);
            }

            InboundConnection inb = con as InboundConnection;

            if (inb != null && inb.ServerUser != null)
            {
                inb.ServerUser.MyConnection = null;
            }

            Log1.Logger("Server.Login").Info("Untracking socket " + conId.ToString());

            bool haveIt = false;

            if (Clients.ContainsKey(conId))
            {
                haveIt = true;
                PerfMon.IncrementCustomCounter("Live Connections", -1);
            }

            Clients.Remove(conId);
            return(haveIt);
        }
예제 #3
0
        /// <summary>
        /// Override from ServerBase, to make sure we create the proper connection object for inbound connections.
        /// If we don't override this method, a generic InboundConnection class will be instantiated.
        /// </summary>
        protected override InboundConnection CreateInboundConnection(Socket s, ServerBase server, int serviceID, bool isBlocking)
        {
            InboundConnection con = null;

            // ServiceIDs represents the type connection that is being requested.
            // these IDs are set in the App.Config of the initiating server and are any arbitrarily agreed upon integers
            switch (serviceID)
            {
            case 7:
                con           = new ZeusInboundConnection(s, server, isBlocking);
                con.ServiceID = serviceID;
                break;

            case 1:     // central server
                con           = new GSTurnedLobbyInboundCentralConnection(s, server, isBlocking);
                con.ServiceID = serviceID;
                GameManager.Instance.CentralServer = con as GSInboundServerConnection;
                break;

            default:     // assume player client
                con           = new GSTurnedLobbyInboundPlayerConnection(s, server, isBlocking);
                con.ServiceID = serviceID;
                break;
            }

#if DEBUG
            if (con == null)
            {
                throw new ArgumentOutOfRangeException("ServiceID " + serviceID.ToString() + " is unknown to CreateInboundConnection.  Cannot process connection.");
            }
#endif
            return(con);
        }
예제 #4
0
 static void ParentConnection_Disconnected(InboundConnection con, string msg)
 {
     ParentConnections.Remove(con.ServerUser.AccountName.ToLower());
     if (ParentDisconnected != null)
     {
         ParentDisconnected(con, msg);
     }
 }
예제 #5
0
        /// <summary>
        /// Grabs the parent connection, given a specific server account name.
        /// </summary>
        /// <param name="accountName"></param>
        /// <returns></returns>
        public static InboundConnection GetParentConnection(string accountName)
        {
            InboundConnection con = null;

            if (ParentConnections.TryGetValue(accountName.ToLower(), out con))
            {
                return(con);
            }
            return(null);
        }
예제 #6
0
        /// <summary>
        /// Checks if a given parent server is alive and can receive communications from us
        /// </summary>
        /// <param name="serverAccountName">the account name of the parent server</param>
        /// <returns>true if the server can be communicated with</returns>
        public static bool IsParentServerConnected(string serverAccountName)
        {
            InboundConnection con = null;

            if (ParentConnections.TryGetValue(serverAccountName.ToLower(), out con))
            {
                return(con.IsAlive);
            }

            return(false);
        }
예제 #7
0
        /// <summary>
        /// Each server in the cluster can have one parent.  Whenever the parent connects, we call this method.
        /// </summary>
        public static void AddParentConnection(InboundConnection client, ServerUser su)
        {
            InboundConnection con = null;

            if (ParentConnections.TryGetValue(client.ServerUser.AccountName.ToLower(), out con))
            {
                con.KillConnection("Parent server logging in again from different connection.");
                con.Disconnected -= new InboundConnection.DisconnectedDelegate(ParentConnection_Disconnected);
                ParentConnections.Remove(con.ServerUser.AccountName.ToLower());
            }

            ParentConnections.Add(client.ServerUser.AccountName.ToLower(), client);
            client.Disconnected += new InboundConnection.DisconnectedDelegate(ParentConnection_Disconnected);
        }
예제 #8
0
 static void ParentConnection_Disconnected(InboundConnection con, string msg)
 {
     ParentConnections.Remove(con.ServerUser.AccountName.ToLower());
     if (ParentDisconnected != null)
     {
         ParentDisconnected(con, msg);
     }
 }
예제 #9
0
        /// <summary>
        /// Each server in the cluster can have one parent.  Whenever the parent connects, we call this method.
        /// </summary>
        public static void AddParentConnection(InboundConnection client, ServerUser su)
        {
            InboundConnection con = null;
            if (ParentConnections.TryGetValue(client.ServerUser.AccountName.ToLower(), out con))
            {
                con.KillConnection("Parent server logging in again from different connection.");
                con.Disconnected -= new InboundConnection.DisconnectedDelegate(ParentConnection_Disconnected);
                ParentConnections.Remove(con.ServerUser.AccountName.ToLower());
            }

            ParentConnections.Add(client.ServerUser.AccountName.ToLower(), client);
            client.Disconnected += new InboundConnection.DisconnectedDelegate(ParentConnection_Disconnected);
        }
예제 #10
0
파일: ServerBase.cs 프로젝트: kamilion/WISP
        /// <summary>
        /// Create a connection object for an incoming connections.  Should be overridden.
        /// </summary>
        protected virtual InboundConnection CreateInboundConnection(Socket s, ServerBase server, int serviceID, bool isBlocking)
        {
            if (serviceID == 7) // 7eus
            {
                ZeusInboundConnection zcon = new ZeusInboundConnection(s, server, isBlocking);
                return zcon;
            }

            InboundConnection newClient = new InboundConnection(s, server, isBlocking);
            return newClient;
        }
예제 #11
0
 static void InboundConnectionManager_ParentDisconnected(InboundConnection con, string msg)
 {
     Log.LogMsg("Incoming server connection lost.  " + ((InboundServerConnection)con).ServerUser.AccountName + ". " + msg);
 }
예제 #12
0
 static void InboundConnectionManager_ParentDisconnected(InboundConnection con, string msg)
 {
     Log.LogMsg("Incoming server connection lost.  " + ((InboundServerConnection)con).ServerUser.AccountName + ". " + msg);
 }