Exemple #1
0
        public override void ExecuteCommand(ComSession session, StringRequestInfo requestInfo)
        {
            PlayServer Server = session.AppServer as PlayServer;

            if (Server == null)
            {
                session.Send("ERRO System Error");
            }
            if (requestInfo.Parameters.Length < 2)
            {
                session.Send("ERRO Parameter imcomplete");
            }
            string name, password;

            name     = requestInfo[0];
            password = requestInfo[1];
            if (name.Length > 32)
            {
                session.Send("ERRO Too long name");
                return;
            }
            if (!Server.Register(name, password))
            {
                session.Send("ERRO Register fail");
            }
            else
            {
                session.Send("INFO Register successfully");
            }
        }
Exemple #2
0
        public void ResetPlayInfo()
        {
            PlayServer server = this.AppServer as PlayServer;

            Commited = false;
            //CommitNumber = new double[server.CommitAmount];
        }
Exemple #3
0
        public override void ExecuteCommand(ComSession session, StringRequestInfo requestInfo)
        {
            PlayServer Server = session.AppServer as PlayServer;

            if (Server == null)
            {
                session.Send("ERRO System Error");
            }
            session.Close();
        }
Exemple #4
0
        public override void ExecuteCommand(ComSession session, StringRequestInfo requestInfo)
        {
            PlayServer Server = session.AppServer as PlayServer;

            Monitor.LogCommit("user " + session.UserId + " " + requestInfo.Key + " " + requestInfo.Body);
            if (Server == null)
            {
                session.Send("ERRO System Error");
                return;
            }
            if (session.UserId == null)
            {
                session.Send("ERRO User did not login");
                return;
            }
            if (Server.GameStarted == false)
            {
                session.Send("ERRO Game have not start");
                return;
            }
            if (session.Commited == true)
            {
                session.Send("ERRO Over Time");
                return;
            }
            else if (requestInfo.Parameters.Length < 1)
            {
                session.Send("ERRO No Number");
                return;
            }
            try
            {
                int ValidNumber = Math.Min(Server.CommitAmount, requestInfo.Parameters.Length);
                session.CommitNumber = new double[ValidNumber];
                for (int i = 0; i < ValidNumber; ++i)
                {
                    double tmp = Convert.ToDouble(requestInfo.Parameters[i]);
                    if (tmp > 100 || tmp < 1)
                    {
                        session.CommitNumber = null;
                        session.Send("ERRO Number is beyond the limited range");
                        return;
                    }
                    session.CommitNumber[i] = tmp;
                }
                session.Commited = true;
                session.Send("INFO Commit successfully");
            }
            catch
            {
                session.Send("ERRO Number too long or Wrong Format");
            }
        }
Exemple #5
0
        public override void ExecuteCommand(ComSession session, StringRequestInfo requestInfo)
        {
            PlayServer Server = session.AppServer as PlayServer;

            if (Server == null)
            {
                session.Send("ERRO System Error");
            }
            if (session.UserId == null)
            {
                session.Send("ERRO didn't login");
            }
            else
            {
                Server.Logout(session.UserId);
                session.Send("INFO Log out completed");
                session.UserId = null;
            }
        }
Exemple #6
0
        public override void ExecuteCommand(ComSession session, StringRequestInfo requestInfo)
        {
            PlayServer Server = session.AppServer as PlayServer;

            if (Server == null)
            {
                session.Send("ERRO System Error");
                return;
            }
            if (requestInfo.Parameters.Length < 2)
            {
                session.Send("ERRO Parameter imcomplete");
                return;
            }
            if (!Server.LoginPermission)
            {
                session.Send("ERRO not permit login");
                return;
            }
            string name, password;

            name     = requestInfo[0];
            password = requestInfo[1];
            if (Server.Login(name, password))
            {
                session.UserId = name;
#if TRACE
                Monitor.Print(name + " login System from ip " + session.RemoteEndPoint.Address.ToString());
                Monitor.LogCommit(requestInfo.Key + " " + requestInfo.Body);
#endif
                session.Send("INFO login successfully");
            }
            else
            {
                Monitor.Print("Entiy from ip " + session.RemoteEndPoint.Address + " try to login with name " + name + " Failed");
                session.Send("ERRO login fail");
            }
        }
Exemple #7
0
        public override void ExecuteCommand(ComSession session, StringRequestInfo requestInfo)
        {
            PlayServer Server = session.AppServer as PlayServer;

            if (Server == null)
            {
                session.Send("ERRO System Error");
                return;
            }
            if (requestInfo.Parameters.Length < 2)
            {
                session.Send("ERRO Parameter imcomplete");
                return;
            }
            if (!Server.LoginPermission)
            {
                session.Send("ERRO not permit login");
                return;
            }
            string name, password;

            name     = requestInfo[0];
            password = requestInfo[1];
            if (Server.Login(name, password))
            {
                session.UserId = name;
#if TRACE
                Console.WriteLine(DateTime.Now.ToLongTimeString() + " " + name + " login System from ip " + session.Config.Ip);
#endif
                session.Send("INFO login successfully");
            }
            else
            {
                session.Send("ERRO login fail");
            }
        }
Exemple #8
0
        public override void ExecuteCommand(ComSession session, StringRequestInfo requestInfo)
        {
            PlayServer Server = session.AppServer as PlayServer;

            if (Server == null)
            {
                session.Send("ERRO System Error");
                return;
            }
            if (Server.GameStarted == false)
            {
                session.Send("ERRO Game have not start");
                return;
            }
            if (session.Commited == true)
            {
                session.Send("ERRO Over Time");
                return;
            }
            else if (requestInfo.Parameters.Length < 1)
            {
                session.Send("ERRO No Number");
                return;
            }
            try
            {
                int    ValidNumber = Math.Min(Server.CommitAmount, requestInfo.Parameters.Length);
                double tmp         = Convert.ToDouble(requestInfo.Parameters[0]);
                session.CommitNumber = tmp;
                session.Commited     = true;
            }
            catch
            {
                session.Send("ERRO Number too long or Wrong Format");
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();
            AppServer a = new AppServer();

            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var        result = bootstrap.Start();
            var        ws     = bootstrap.GetServerByName("WSServer");
            var        ds     = bootstrap.GetServerByName("DistributeServer");
            PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);

            // connect the server
            Server.DisplayServer = ws as WebSocketTest.WSServer;
            Server.Distribute    = ds as DistributeServer;

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");

            /*
             * while (Console.ReadKey().KeyChar != 'q')
             * {
             *  Console.WriteLine();
             *  continue;
             * }
             */
            while (true)
            {
                string str = Console.ReadLine();
                str = str.Trim();
                if (str == "start")
                {
                    //PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);
                    if (Server.GameStarted)
                    {
                        Console.WriteLine("Game has started");
                    }
                    else
                    {
                        Server.GameStart();
                        Console.WriteLine("Game Start!");
                    }
                }

                switch (str)
                {
                case "clearIpSec":
                    Server.IPFilter.Clear(); break;

                case "pause":
                    Server.GamePause(); break;

                case  "resume":
                    Server.GameResume(); break;

                case "end":
                    Server.GameEnd(); break;

                case "show":
                    Console.WriteLine("Current Session Number: {0}", Server.SessionCount);
                    Server.PrintPlayers();
                    Console.WriteLine("Current WebSession NUmber: {0}", ws.SessionCount);
                    break;

                case "clear":
                    foreach (var session in Server.GetAllSessions())
                    {
                        session.Close();
                    }
                    break;
                }
                if (str == "q")
                {
                    break;
                }
            }
            Monitor.flush();
            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
        }
Exemple #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();
            AppServer a = new AppServer();

            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var        result = bootstrap.Start();
            var        ws     = bootstrap.GetServerByName("WSServer");
            PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);

            Server.DisplayServer = ws as WebSocketTest.WSServer;

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");

            /*
             * while (Console.ReadKey().KeyChar != 'q')
             * {
             *  Console.WriteLine();
             *  continue;
             * }
             */
            while (true)
            {
                string str = Console.ReadLine();
                str = str.Trim();
                if (str == "start")
                {
                    //PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);
                    if (Server.GameStarted)
                    {
                        Console.WriteLine("Game has started");
                    }
                    else
                    {
                        Server.GameStart();
                        Console.WriteLine("Game Start!");
                    }
                }
                if (str == "q")
                {
                    break;
                }
                if (str == "end")
                {
                    //PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);
                    Server.GameEnd();
                }
            }
            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
        }