Implements a single Poker Server instance, with various game functions / game data storage.
Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the Client class with the specified game server and underlying web socket connection.
        /// </summary>
        /// <param name="parent">The game server that this client is connected to.</param>
        /// <param name="connection">The underlying web socket connection that is associated with this client.</param>
        public Client(CardServer parent, WebSocketConnection connection)
        {
            Info     = new ClientInfo();
            server   = parent;
            thisType = this.GetType();

            conn = connection;

            // Web socket event hookup (not really events).
            conn.OnMessage = ReceiveMessage;
            conn.OnOpen    = Connected;
            conn.OnClose   = Disconnected;

            Info.ID = Guid.NewGuid().ToString();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the Client class with the specified game server and underlying web socket connection.
        /// </summary>
        /// <param name="parent">The game server that this client is connected to.</param>
        /// <param name="connection">The underlying web socket connection that is associated with this client.</param>
        public Client(CardServer parent, WebSocketConnection connection)
        {
            Info = new ClientInfo();
            server = parent;
            thisType = this.GetType();

            conn = connection;

            // Web socket event hookup (not really events).
            conn.OnMessage = ReceiveMessage;
            conn.OnOpen = Connected;
            conn.OnClose = Disconnected;

            Info.ID = Guid.NewGuid().ToString();
        }
Esempio n. 3
0
        /// <summary>
        /// Entry point for the application.
        /// </summary>
        /// <param name="args">
        /// Command-line arguments for this console application are as follows:
        ///
        /// Param 1: Server name. Cannot contain spaces. Valid characters are A-Z, a-z, 0-9, _, -, and .
        /// Param 2: Port number. Must be between 1000 and 65535.
        /// Param 3: Admin password. Cannot contain spaces.
        ///
        /// A sample run might look like this, if invoked manually: C:\> PokerServer.exe MyName 8500 MyPass
        /// </param>
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                ExitWithError("Invalid number of command-line arguments (Password can not contain spaces).");
            }

            int portNumber;

            if (!int.TryParse(args[1], out portNumber))
            {
                ExitWithError("Port number is invalid.");
            }
            if (portNumber < 1000 || portNumber > 65535)
            {
                ExitWithError("Port number is outside valid range [1000-65535].");
            }
            if (!Regex.IsMatch(args[0], @"^[a-zA-Z0-9_\-.]+$"))
            {
                ExitWithError("Name is invalid. Valid name characters are A-Z, a-z, 0-9, _, -, and .");
            }

            Name = args[0];
            Port = portNumber;

            // Set up the named pipe server and the initial async connection listener.
            NamedPipeServerStream nps = new NamedPipeServerStream("wss" + Process.GetCurrentProcess().Id, PipeDirection.Out, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);

            nps.BeginWaitForConnection(PipeHandler, nps);

            cs = new CardServer(args[2]);

            server = new Fleck.WebSocketServer("ws://" + Environment.MachineName + ":" + Port + "/");
            server.Start(s => cs.NewClient((WebSocketConnection)s));

            while (true)
            {
                Console.ReadKey();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Entry point for the application.
        /// </summary>
        /// <param name="args">
        /// Command-line arguments for this console application are as follows:
        /// 
        /// Param 1: Server name. Cannot contain spaces. Valid characters are A-Z, a-z, 0-9, _, -, and .
        /// Param 2: Port number. Must be between 1000 and 65535.
        /// Param 3: Admin password. Cannot contain spaces.
        /// 
        /// A sample run might look like this, if invoked manually: C:\> PokerServer.exe MyName 8500 MyPass
        /// </param>
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                ExitWithError("Invalid number of command-line arguments (Password can not contain spaces).");
            }

            int portNumber;
            if (!int.TryParse(args[1], out portNumber))
            {
                ExitWithError("Port number is invalid.");
            }
            if (portNumber < 1000 || portNumber > 65535)
            {
                ExitWithError("Port number is outside valid range [1000-65535].");
            }
            if (!Regex.IsMatch(args[0], @"^[a-zA-Z0-9_\-.]+$"))
            {
                ExitWithError("Name is invalid. Valid name characters are A-Z, a-z, 0-9, _, -, and .");
            }

            Name = args[0];
            Port = portNumber;

            // Set up the named pipe server and the initial async connection listener.
            NamedPipeServerStream nps = new NamedPipeServerStream("wss" + Process.GetCurrentProcess().Id, PipeDirection.Out, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
            nps.BeginWaitForConnection(PipeHandler, nps);

            cs = new CardServer(args[2]);

            server = new Fleck.WebSocketServer("ws://" + Environment.MachineName + ":" + Port + "/");
            server.Start(s => cs.NewClient((WebSocketConnection)s));

            while (true)
            {
                Console.ReadKey();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Entry point for the application.
        /// </summary>
        /// <param name="args">
        /// Command-line arguments for this console application are as follows:
        ///
        /// Param 1: Server name. Cannot contain spaces. Valid characters are A-Z, a-z, 0-9, _, -, and .
        /// Param 2: Port number. Must be between 1000 and 65535.
        /// Param 3: Admin password. Cannot contain spaces.
        ///
        /// A sample run might look like this, if invoked manually: C:\> PokerServer.exe MyName 8500 MyPass
        /// </param>
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                args    = new string[4];
                args[0] = "FC";
                args[1] = "8000";
                args[2] = "abcd";
                args[3] = "127.0.0.1";

                Console.WriteLine("Enter Room Name:");
                args[0] = Console.ReadLine();
                Console.WriteLine("Enter Port No Bet 8000 & 9000:");
                args[1] = Console.ReadLine();
                Console.WriteLine("Enter Room Password:"******"Enter Hosting IP or D for auto detect:");
                args[3] = Console.ReadLine();
            }

            int portNumber;

            if (!int.TryParse(args[1], out portNumber))
            {
                ExitWithError("Port number is invalid.");
            }
            if (portNumber < 1000 || portNumber > 65535)
            {
                ExitWithError("Port number is outside valid range [1000-65535].");
            }
            if (!Regex.IsMatch(args[0], @"^[a-zA-Z0-9_\-.]+$"))
            {
                ExitWithError("Name is invalid. Valid name characters are A-Z, a-z, 0-9, _, -, and .");
            }

            Name = args[0];
            Port = portNumber;
            if (args[3].Equals("D"))
            {
                if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                {
                    throw new Exception("Network not available.");
                }

                IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());

                MachineIp = host
                            .AddressList
                            .FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork).ToString();
            }
            else
            {
                MachineIp = args[3];
            }

            // Set up the named pipe server and the initial async connection listener.
            NamedPipeServerStream nps = new NamedPipeServerStream("wss" + Process.GetCurrentProcess().Id, PipeDirection.Out, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);

            nps.BeginWaitForConnection(PipeHandler, nps);

            cs = new CardServer(args[2]);

            try
            {
                //server = new Fleck.WebSocketServer("ws://" + Environment.MachineName + ":" + Port + "/");
                server = new Fleck.WebSocketServer("ws://" + MachineIp + ":" + Port + "/");
                server.Start(s => cs.NewClient((WebSocketConnection)s));
                Console.WriteLine("PID: " + Process.GetCurrentProcess().Id);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }

            while (true)
            {
                Console.ReadKey();
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Closes the web socket connection and disposes of this client.
 /// </summary>
 public void Dispose()
 {
     if (conn != null)
     {
         conn.Close(0);
         conn = null;
     }
     server = null;
     thisType = null;
     Info = null;
 }