Ejemplo n.º 1
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                NetState ns = e.State;
                Socket   s  = ns.Socket;

                IPEndPoint ipep = (IPEndPoint)s.LocalEndPoint;

                IPAddress localAddress = ipep.Address;
                int       localPort    = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)s.RemoteEndPoint;
                    if (!IsPrivateNetwork(ipep.Address) && m_PublicAddress != null)
                    {
                        localAddress = m_PublicAddress;
                    }
                }

                // name can only be this long:
                //          "---------------"
                e.AddServer("Angel Island", new IPEndPoint(localAddress, SocketOptions.AngelIslandPort));
                //e.AddServer("Siege Perilous", new IPEndPoint(localAddress, SocketOptions.SiegePort));
                //e.AddServer("Mortalis", new IPEndPoint(localAddress, SocketOptions.MortalisPort));				// RIP - For now!
                //e.AddServer("AI Resurrection", new IPEndPoint(localAddress, SocketOptions.AIResurrectionPort));
                //e.AddServer("AI Test Center", new IPEndPoint(localAddress, SocketOptions.TestCenterPort));
                //e.AddServer("SP Test Center", new IPEndPoint(localAddress, SocketOptions.EventShardPort));
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 2
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                NetState ns = e.State;
                Socket   s  = ns.Socket;

                IPEndPoint ipep = (IPEndPoint)s.LocalEndPoint;

                IPAddress localAddress = ipep.Address;
                int       localPort    = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)s.RemoteEndPoint;
                    if (!IsPrivateNetwork(ipep.Address) && m_PublicAddress != null)
                    {
                        localAddress = m_PublicAddress;
                    }
                }
                Console.WriteLine("Players connecting to IP: {0}", localAddress);
                e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 3
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                var ns = e.State;

                var ipep = (IPEndPoint)ns.Connection?.LocalEndPoint;
                if (ipep == null)
                {
                    return;
                }

                var localAddress = ipep.Address;
                var localPort    = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)ns.Connection.RemoteEndPoint;
                    if (ipep == null || !IsPrivateNetwork(ipep.Address) && _publicAddress != null)
                    {
                        localAddress = _publicAddress;
                    }
                }

                e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));
            }
            catch (Exception er)
            {
                logger.Warning(er, "Unhandled exception at server list");
                e.Rejected = true;
            }
        }
Ejemplo n.º 4
0
        // ==================================================================================
        // The serverlist event
        // ==================================================================================
        public static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                // ----------------------------------------------------
                // Lets find internet ip
                // ----------------------------------------------------
                DetectInternetIP();

                // ----------------------------------------------------
                // Find the server ip to use for this user
                // ----------------------------------------------------
                IPAddress ipAddr = FindMachineIP(e);

                // ----------------------------------------------------
                // Send serverlist
                // ----------------------------------------------------
                if (ipAddr != null)
                {
                    e.AddServer(ServerName, new IPEndPoint(ipAddr, 2593)); //  Place the port that you are using here.
                }
                else
                {
                    e.Rejected = true;
                }
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 5
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                var ns = e.State;
                var s  = ns.Socket;

                var ipep = (IPEndPoint)s.LocalEndPoint;

                var localAddress = ipep.Address;
                var localPort    = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)s.RemoteEndPoint;

                    if (!IsPrivateNetwork(ipep.Address) && _PublicAddress != null)
                    {
                        localAddress = _PublicAddress;
                    }
                }

                e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 6
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                NetState   ns           = e.State;
                Socket     s            = ns.Socket;
                IPEndPoint ipep         = (IPEndPoint)s.LocalEndPoint;
                IPAddress  localAddress = ipep.Address;
                int        localPort    = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)s.RemoteEndPoint;

                    if (!IsPrivateNetwork(ipep.Address) && _PublicAddress != null)
                    {
                        localAddress = _PublicAddress;
                    }
                }

                e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));
            }
            catch (Exception x)
            {
                x.ToConsole();
                e.Rejected = true;
            }
        }
Ejemplo n.º 7
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                var ns = e.State;

                var ipep = (IPEndPoint)ns.Connection.LocalEndPoint;

                var localAddress = ipep.Address;
                var localPort    = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)ns.Connection.RemoteEndPoint;
                    if (!IsPrivateNetwork(ipep.Address) && m_PublicAddress != null)
                    {
                        localAddress = m_PublicAddress;
                    }
                }

                e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));
            }
            catch (Exception er)
            {
                Console.WriteLine(er);
                e.Rejected = true;
            }
        }
Ejemplo n.º 8
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                NetState ns = e.State;
                Socket s = ns.Socket;

                IPEndPoint ipep = (IPEndPoint)s.LocalEndPoint;

                IPAddress localAddress = ipep.Address;
                int localPort = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)s.RemoteEndPoint;
                    if (!IsPrivateNetwork(ipep.Address) && m_PublicAddress != null)
                        localAddress = m_PublicAddress;
                }

                e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 9
0
 internal void ReceivedServerList(object sender, ServerListEventArgs e)
 {
     if (OnReceiveServerList != null)
     {
         OnReceiveServerList(sender, e);
     }
 }
Ejemplo n.º 10
0
        public static void AccountLogin_ReplyAck(NetState state)
        {
            ServerListEventArgs e = new ServerListEventArgs(state, state.Account);

            try {
                EventSink.InvokeServerList(e);
            } catch (Exception ex) {
                Console.WriteLine("Exception disarmed in ServerList: {0}", ex);
                e.Rejected = true;
            }

            if (e.Rejected)
            {
                state.Account = null;
                state.Send(new AccountLoginRej(ALRReason.BadComm));
                state.Dispose();
            }
            else
            {
                ServerInfo[] info = (ServerInfo[])e.Servers.ToArray(typeof(ServerInfo));

                state.ServerInfo = info;

                state.Send(new AccountLoginAck(info));
            }
        }
Ejemplo n.º 11
0
        private static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                NetState ns = e.State;
                Socket   s  = ns.Socket;

                IPEndPoint ipep = (IPEndPoint)s.LocalEndPoint;

                IPAddress localAddress = ipep.Address;
                int       localPort    = ipep.Port;

                if (IsPrivateNetwork(localAddress))
                {
                    ipep = (IPEndPoint)s.RemoteEndPoint;
                    if (!IsPrivateNetwork(ipep.Address) && m_PublicAddress != null)
                    {
                        localAddress = m_PublicAddress;
                    }
                }

                e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));

                /*IPAddress testAddress;
                 * IPAddress.TryParse("127.0.0.1", out testAddress);
                 * e.AddServer("Test Center", new IPEndPoint(testAddress, 2594));*/
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 12
0
        // ==================================================================================
        // Calculates what server IP to use
        // ==================================================================================
        public static IPAddress FindMachineIP(ServerListEventArgs e)
        {
            // ----------------------------------------------------
            // Find the IP of the connecting user
            // ----------------------------------------------------
            Socket    sock         = e.State.Socket;
            IPAddress theirAddress = ((IPEndPoint)sock.RemoteEndPoint).Address;
            IPAddress serverAddress;

            // ----------------------------------------------------
            // Is it Loopback?
            // ----------------------------------------------------
            if (IPAddress.IsLoopback(theirAddress))
            {
                return(IPAddress.Parse("127.0.0.1"));
            }

            // ----------------------------------------------------
            // Local
            // ----------------------------------------------------
            UInt32 uint32Address = StringIPToUInt32IP(theirAddress.ToString());

            for (UInt32 LocalLanIPRangesLoop = 0; LocalLanIPRangesLoop < LocalLanIPRangesCount; LocalLanIPRangesLoop++)
            {
                if ((LocalLanIPRanges[LocalLanIPRangesLoop].RangeFrom <= uint32Address) && (LocalLanIPRanges[LocalLanIPRangesLoop].RangeTo >= uint32Address))
                {
                    Resolve(Dns.GetHostName(), out serverAddress);

                    Console.WriteLine("Player is reconnecting to " + serverAddress.ToString());
                    return(serverAddress);
                }
            }

            // ----------------------------------------------------
            // Internet addresses
            // ----------------------------------------------------
            if (Address != null)
            {
                Resolve(Address, out serverAddress);
            }
            else
            {
                Resolve(Dns.GetHostName(), out serverAddress);
            }

            Console.WriteLine("Player is reconnecting to " + serverAddress.ToString());
            return(serverAddress);
        }
Ejemplo n.º 13
0
        public static void EventSink_ServerList( ServerListEventArgs e )
        {
            try
            {
                IPAddress ipAddr;

                if ( Resolve( Address, out ipAddr ) )
                    e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
                else
                    e.Rejected = true;
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 14
0
        public static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                IPAddress ipAddr;

                if (Resolve(Address, out ipAddr))
                {
                    e.AddServer(ServerName, new IPEndPoint(ipAddr, Listener.Port));
                }
                else
                {
                    e.Rejected = true;
                }
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 15
0
        public static void EventSink_ServerList(ServerListEventArgs e)
        {
            try
            {
                IPAddress ipAddr;

                if (Resolve(Address != null && !IsLocalMachine(e.State) ? Address : Dns.GetHostName(), out ipAddr))
                {
                    e.AddServer(ServerName, new IPEndPoint(ipAddr, Listener.Port));
                }
                else
                {
                    e.Rejected = true;
                }
            }
            catch
            {
                e.Rejected = true;
            }
        }
Ejemplo n.º 16
0
 public static void EventSink_ServerList(ServerListEventArgs e)
 {
     try
     {
         if (Core.Config.GameServers.Count == 0)
         {
             e.AddServer(ServerName, (IPEndPoint)e.State.Socket.LocalEndPoint);
         }
         else
         {
             foreach (Config.GameServer gs in Core.Config.GameServers)
             {
                 e.AddServer(gs.Name, gs.Address);
             }
         }
     }
     catch (Exception ex)
     {
         log.Fatal(ex);
         e.Rejected = true;
     }
 }
Ejemplo n.º 17
0
        public void AccountLogin_ReplyAck( GameClient state )
        {
            ServerListEventArgs e = new ServerListEventArgs( state, state.Account );

            try
            {
                EventSink.Instance.InvokeServerList( e );
            }
            catch ( Exception ex )
            {
                Logger.Error( "Exception disarmed in ServerList: {0}", ex );
                e.Rejected = true;
            }

            if ( e.Rejected )
            {
                state.Account = null;
                state.Send( new AccountLoginRej( ALRReason.BadComm ) );
                state.Dispose();
            }
            else
            {
                ServerInfo[] info = e.Servers.ToArray();

                state.ServerInfo = info;

                state.Send( new AccountLoginAck( info ) );
            }
        }
Ejemplo n.º 18
0
		public static void AccountLogin_ReplyAck( NetState state )
		{
			ServerListEventArgs e = new ServerListEventArgs( state, state.Account );

			EventSink.InvokeServerList( e );

			if ( e.Rejected )
			{
				state.Account = null;
				state.Send( new AccountLoginRej( ALRReason.BadComm ) );
				state.Dispose();
			}
			else
			{
				ServerInfo[] info = e.Servers.ToArray();

				state.ServerInfo = info;

				state.Send( new AccountLoginAck( info ) );
			}
		}
		public static void AccountLogin_ReplyAck( NetState state )
		{
			ServerListEventArgs e = new ServerListEventArgs( state, state.Account );

			try {
				EventSink.InvokeServerList(e);
			} catch (Exception ex) {
				log.Fatal("Exception disarmed in ServerList", ex);
				e.Rejected = true;
			}

			if ( e.Rejected )
			{
				state.Account = null;
				state.Send( new AccountLoginRej( ALRReason.BadComm ) );
				state.Dispose();
			}
			else
			{
				ServerInfo[] info = (ServerInfo[])e.Servers.ToArray( typeof( ServerInfo ) );

				state.ServerInfo = info;

				state.Send( new AccountLoginAck( info ) );
			}
		}
Ejemplo n.º 20
0
 public void InvokeServerList( ServerListEventArgs e )
 {
     if ( ServerList != null )
         ServerList( e );
 }
Ejemplo n.º 21
0
 private static void EventSink_OnServerList(ServerListEventArgs args)
 {
     args.State.Send(new UltimaLive.Network.LoginComplete());
     args.State.Send(new UltimaLive.Network.MapDefinitions());
 }