/// <summary>
 /// Creates a new socket client.
 /// </summary>
 /// <param name="acceptedsocket">The socket associated with it.</param>
 /// <param name="socketEvents">The socket events associated with the server.</param>
 public SocketClient(Socket acceptedsocket, SocketEvents socketEvents)
 {
     clientSocket = acceptedsocket;
     //clientSocket.SendBufferSize = 1024;
     this.socketEvents = socketEvents;
     System.Threading.Interlocked.CompareExchange(ref send_lock, new object(), null);
 }
        /// <summary>
        /// Creates a new socket server.
        /// </summary>
        /// <param name="socketEvents">The events associated with the server. Put null for nothing.</param>
        public SocketServer(SocketEvents socketEvents)
        {
            if (socketEvents == null)
                this.socketEvents = new SocketEvents();
            else
                this.socketEvents = socketEvents;

            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        }
Beispiel #3
0
        /// <summary>
        /// Program Entry.
        /// </summary>
        /// <param name="args">Process arguments.</param>
        public static void Main(string[] args)
        {
            Console.Title = "ProjectX V3 - Auth Server";
            try
            {
                config = new XmlConfig();
                config.LoadConfig(Database.ServerDatabase.DatabaseLocation + "\\Config.xml");
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not load the config.");
                Console.WriteLine("Error:");
                Console.WriteLine(e);
                Console.ReadLine();
                return;
            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Starting the server...");
            try
            {
                SocketEvents sockEvents = new SocketEvents();
                sockEvents.OnConnection = new ConnectionEvent(Network.NetworkConnections.Handle_Connection);
                sockEvents.OnReceive = new BufferEvent(Network.NetworkConnections.Handle_Receive);
                int[] ports;
                config.ReadString("Ports").Split(',').ConverToInt32(out ports);
                foreach (int port in ports)
                    BeginServer(sockEvents, port);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("The server is open...");
                Console.ResetColor();

                while (true)
                    Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Could not open the server...");
                Console.WriteLine(e.ToString());
                Console.ReadLine();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Starts the game auth server.
        /// </summary>
        public static void Start()
        {
            SocketEvents socketEvents = new SocketEvents();
            socketEvents.OnReceive = new BufferEvent(HandlePacket);
            SocketServer gameauth = new SocketServer(socketEvents);
            gameauth.Start(Program.Config.ReadString("IPAddress"), Program.Config.ReadInt32("AuthPort"));

            // thread to clean for login : CHECK if UIDCollection contains the entity id at login (before adding to kernel.clients and before ANSWER_OK)
            new System.Threading.Thread(() =>
                                        {
                                            while (true)
                                            {
                                                try
                                                {
                                                    int failed;
                                                    UIDCollection.TryForeachAction((key1, time) =>
                                                                                   {
                                                                                   	try
                                                                                   	{
                                                                                   		if (DateTime.Now >= time)
                                                                                   		{
                                                                                   			int tries = 0;
                                                                                   			while (!UIDCollection.TryRemove(key1) && tries <= 3)
                                                                                   			{
                                                                                   				tries++;
                                                                                   				System.Threading.Thread.Sleep(20);
                                                                                   			}
                                                                                   		}
                                                                                   	}
                                                                                   	catch { }
                                                                                   }, out failed);
                                                    if (failed > 0)
                                                        Console.WriteLine("{0} failed to be removed from the login queue.", failed);
                                                }
                                                catch { }
                                                System.Threading.Thread.Sleep(25000);
                                            }
                                        }).Start();
        }
Beispiel #5
0
        /// <summary>
        /// Program entry.
        /// </summary>
        /// <param name="args">Process arguments.</param>
        public static void Main(string[] args)
        {
            Console.Title = "ProjectX V3 - Game Server";

            try
            {
                config = new XmlConfig();
                config.LoadConfig(Database.ServerDatabase.DatabaseLocation + "\\Config.xml");
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not load the config.");
                Console.WriteLine("Error:");
                Console.WriteLine(e);
                Console.ReadLine();
                return;
            }

            if (!Database.ServerDatabase.Load())
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Could not load the database.");
                Console.ReadLine();
                return;
            }

            Threads.GlobalThreads.Start();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Starting the server...");
            try
            {
                Network.GameAuth.Start();
                SocketEvents sockEvents = new SocketEvents();
                sockEvents.OnConnection = new ConnectionEvent(Network.NetworkConnections.Handle_Connection);
                sockEvents.OnDisconnection = new ConnectionEvent(Network.NetworkConnections.Handle_Disconnection);
                sockEvents.OnReceive = new BufferEvent(Network.NetworkConnections.Handle_Receive);
                BeginServer(sockEvents, config.ReadInt32("GamePort"));

                ProjectX_V3_Lib.Native.Kernel32.SetConsoleCtrlHandler(
                    new ProjectX_V3_Lib.Native.Kernel32.ConsoleEventHandler(Console_CloseEvent),
                    true);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("The server is open...");
                Console.ResetColor();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Could not open the server...");
                Console.WriteLine(e.ToString());
                Console.ReadLine();
                return;
            }

            while (true)
                HandleCmd(Console.ReadLine());
        }
Beispiel #6
0
 /// <summary>
 /// Begins the server.
 /// </summary>
 /// <param name="sockEvents">The socket events.</param>
 /// <param name="port">The port.</param>
 private static void BeginServer(SocketEvents sockEvents, int port)
 {
     AllowConnections = true;
     SocketServer server = new SocketServer(sockEvents);
     server.Start(config.ReadString("IPAddress"), port);
 }