예제 #1
0
        private void ConnectMethod()
        {
            if (InputName.Text == "")
            {
                MessageBox.Show("Incorrect data!");
                ConnectButton.Enabled = true;
                return;
            }
            else
            {
                this.FormBorderStyle       = FormBorderStyle.Sizable;
                this.ControlBox            = true;
                this.Text                  = InputName.Text;
                this.AllABonents.Enabled   = true;
                this.InputMessage.Enabled  = true;
                this.SendButton.Enabled    = true;
                this.OutputMessage.Enabled = true;
                this.ConnectButton.Text    = "Disconnect";
                this.InputName.ReadOnly    = true;

                client      = new ServerClient(new InstanceContext(this));
                userName    = InputName.Text;
                id          = client.Connect(InputName.Text);
                isConnected = true;
                nameInList  = userName + " — Online";
                client.ProvideMessage(id);

                //if (AllABonents.Items.Contains(InputName.Text + " — Offline"))
                //    AllABonents.Items[id] = nameInList;
                //else
                //    AllABonents.Items.Add(nameInList);
                this.ActiveControl = InputMessage;
                InputMessage.Focus();
            }
        }
예제 #2
0
        /// <summary>
        /// 节点操作
        /// </summary>
        /// <param name="nodeName"></param>
        /// <param name="status">1-连接 2-空闲 3-运行</param>
        /// <returns></returns>
        public async Task <bool> NodeSwich(string nodeName, int status)
        {
            var node = GetNodeByName(nodeName);

            if (node == null || node.NodeType == "master")
            {
                return(false);
            }

            _serverClient.Server = node;
            switch (status)
            {
            case 1:
            {
                if (node.Status != 0)
                {
                    return(false);
                }
                var result = await _serverClient.Connect();

                if (result.success)
                {
                    _repositoryFactory.ServerNodes.UpdateBy(x => x.NodeName == nodeName, x => new ServerNodeEntity
                        {
                            AccessSecret   = result.content,
                            LastUpdateTime = DateTime.Now,
                            Status         = 1//连接成功更新为空闲状态
                        });
                    await _unitOfWork.CommitAsync();
                }
                else
                {
                    Log.LogHelper.Warn($"{nodeName}连接异常:{result.content}");
                }
                return(result.success);
            }

            case 2:
            {
                if (node.Status != 2)
                {
                    return(false);
                }
                return(await _serverClient.Shutdown());
            }

            case 3:
            {
                if (node.Status != 1)
                {
                    return(false);
                }
                return(await _serverClient.StartUp());
            }

            default: return(false);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            InstanceContext instanceContext = new InstanceContext(new MessageCallback());
            var             client          = new ServerClient(instanceContext);

            Console.WriteLine("Введите имя для подключения:");
            string name        = Console.ReadLine();
            int    connectId   = client.Connect(name);
            var    allAbonents = client.ShowAbonents(connectId);

            while (true)
            {
                string a = Console.ReadLine();
                if (a == "s")
                {
                    allAbonents = client.ShowAbonents(connectId);
                    foreach (var index in allAbonents)
                    {
                        Console.WriteLine(index.Value.id + " " + index.Value.name + " " + index.Value.status);
                    }
                }
                if (a == "d")
                {
                    client.Disconnect(connectId);
                }
                if (a == "c")
                {
                    client.Connect(name);
                }
                if (a == "send")
                {
                    client.SendMessage(connectId, null, "Привет всем");
                }
                if (a == "p")
                {
                    var d = client.ProvideMessage(connectId);
                    allAbonents = client.ShowAbonents(connectId);
                    foreach (var index in d)
                    {
                        Console.WriteLine(allAbonents[index.SenderId].name + " : " + index.TextOfMessage);
                    }
                }
            }
        }
예제 #4
0
 void ConnectUser()
 {
     if (!isConnected)
     {
         client = new ServerClient(new System.ServiceModel.InstanceContext(this));
         ID     = client.Connect(tbUserName.Text);
         client.ProvideMessage(ID);
         tbUserName.IsEnabled = false;
         bConnDicon.Content   = "Disconnect";
         isConnected          = true;
     }
 }
예제 #5
0
        private static void Main(string[] args)
        {
            var serverClient = new ServerClient();
            serverClient.Connect();
            var chatClient = serverClient.GetChatClient();
            var message = chatClient.Echo("I am so damn good!");
            serverClient.Disconnect();

            Console.WriteLine("Connection was successful!");
            Console.WriteLine("Server returned: {0}", message);
            Console.ReadLine();
        }
예제 #6
0
        private void ConnectMethod()
        {
            if (InputName.Text.Trim() == "")
            {
                MessageBox.Show("Incorrect data!!! Try again");
                return;
            }
            else
            {
                InstanceContext i = new InstanceContext(this);
                client = new ServerClient(i);

                userName    = InputName.Text.Trim();
                id          = client.Connect(userName);
                status      = Status.Online;
                allAbonents = client.ShowAbonents(id);


                OutputMessage.Enabled  = true;
                SendButton.Enabled     = true;
                InputMessage.Enabled   = true;
                AbonentList.Enabled    = true;
                ConnDisconnButton.Text = "Disconnect";
                InputName.ReadOnly     = true;
                ShowButton.Enabled     = true;
                ForAllCheck.Enabled    = true;
                this.Text = userName;

                //Метод работы со списком
                DrawAbonentList(userName, status, allAbonents);

                var h = client.ProvideMessage(id);
                foreach (var index in h)
                {
                    //string recipient = AbonentList.Items[index.RecipientId].ToString();
                    //recipient = recipient.Substring(0, recipient.IndexOf(":"));

                    string recipient = allAbonents[index.SenderId].name;

                    OutputMessage.Text += recipient + ": " + index.TextOfMessage + "\r";
                    //клиент7: Console.WriteLine(allAbonents[index.SenderId].name + " : " + index.TextOfMessage);
                }


                this.ActiveControl = InputMessage;
            }
        }
        public string[] Execute(string[] arguments)
        {
            IPAddress     ip;
            List <string> output = new List <string>();

            if (!client.connected && arguments.Length > 1 && IPAddress.TryParse(arguments[1], out ip))
            {
                client.Connect(ip);
                output.Add("Connecting to server " + arguments[1] + "...");
            }
            else
            {
                if (arguments.Length == 1)
                {
                    output.Add("Can't connect to server.");
                }
                else
                {
                    output.Add("Can't connect to server " + arguments[1] + ".");
                    output.Add("You may be already connected or entered a faulty IP");
                }
            }
            return(output.ToArray());
        }
        protected override void OnStart(string[] args)
        {
            #region depreciated
            //if (MainConfig.CardModeMode != CardModeMode.NoCardNeededDemoMode)
            //{
            //    //while (CardManger == null || CardManger?.IsDisposed == true)
            //    //{
            //    //    try
            //    //    {
            //    //        List<string> Readers = ACR122UManager.GetACR122UReaders();
            //    //        CardManger = new ACR122UManager(Readers[0]);
            //    //    }
            //    //    catch
            //    //    {
            //    //        Logger.WriteLog("Error no card reader detected...Please Replugin a compatable cardreader", LoggerWarringLevel.Danger);
            //    //        MessageBox.Show("Error no card reader detected...\nPlease Replugin a compatable cardreader and click ok.");
            //    //    }
            //    //}


            //    //CardManger.CheckCard = true;

            //    //CardManger.CardDetected += CardDectected;
            //    //CardManger.CardRemoved += CardRemoved;
            //    //CardManger.AcceptedCardScaned += AcceptedCard;
            //    //CardManger.RejectedCardScaned += RejectedCard;
            //    //CardManger.CardStateChanged += CardStateChanged;

            //}
            #endregion

            if (MainConfig.ServerMode != ServerMode.NoServerDemoMode)
            {
                while (!TheServerClient.Connected)
                {
                    try
                    {
                        TheServerClient.Connect();
                        ResponseInfo <GetMachineGamesReturn, ResponseStatus> Return = TheServerClient.GetMachineGames(MainConfig.MachineGUID);
                        GameConfig = new ServiceJSONGamesConfig(Return.Data);
                    }
                    catch (Exception e)
                    {
                        if (e.Message == "Please provide valid credentials,either user name is invalid or password is invalid")
                        {
                            Logger.WriteLog("Access denied due to incorrect password.", LoggerWarringLevel.Danger);
                            MessageBox.Show("Access denied due to incorrect password. Please correct the password now.");
                            EditServerCredential_Click(this, new EventArgs());
                        }
                        else
                        {
                            Logger.WriteLog("Error - Server is not responding. Will try again in 20000ms.", LoggerWarringLevel.Danger);
                            Thread.Sleep(20000);
                        }
                    }
                }
            }
            else
            {
                GameConfig = new ServiceJSONGamesConfig();
            }



            GameStarter = new GameInstancer(GameConfig);

            if (MainConfig.StarterMode == GameStartMode.SingleGameStarter == !MenuRunning)
            {
                GameMenu.StartMenu();
            }

            GameStarter.GameIsStartingEvent += GameInstancerStartingGame;
            GameStarter.GameHasStartedEvent += GameInstancerGameHasStarted;
            GameStarter.GameHasEndedEvent   += GameInstancerGameHasEnded;

            if (MainConfig.CardModeMode != CardModeMode.NoCardNeededDemoMode)
            {
                try
                {
                    NFCReader = new RL8000_NFC();
                    NFCReader.MifareClassicISO1443ACardDetectedEvent += CardDetected;
                }
                catch
                {
                    const string Error = "\nError - Cannot find card reader.\nPlease replug in the card reader.\nWill try again in 20000ms.\n";
                    Logger.WriteLog(Error, LoggerWarringLevel.Danger);
#if !DEBUG
                    DialogResult Result = MessageBox.Show(Error, "Error", MessageBoxButtons.RetryCancel);
                    if (Result == DialogResult.Cancel)
                    {
                        Application.Exit();
                    }
#endif
                    Thread.Sleep(20000);
                }
            }
            else
            {
                try
                {
                    NFCReader = new RL8000_NFC();
                    NFCReader.MifareClassicISO1443ACardDetectedEvent += CardDetected;
                }
                catch
                {}
            }

            if (MainConfig.StarterMode == GameStartMode.MultiSocketStarterMaster)
            {
                while (MasterServer == null)
                {
                    try
                    {
                        MasterServer = new MasterServer(MainConfig.PortNumber);
                        MasterServer.ShowConsole();
                    }
                    catch
                    {
                        const string Error = "\nError - Master Server can not open port.\nPlease Check for Port usage or your config file.\nWill try again in 20000ms.";
                        Logger.WriteLog(Error, LoggerWarringLevel.Danger);
#if !DEBUG
                        DialogResult Result = MessageBox.Show(Error, "Error", MessageBoxButtons.RetryCancel);
                        if (Result == DialogResult.Cancel)
                        {
                            Application.Exit();
                        }
#endif
                        Thread.Sleep(20000);
                    }
                }
            }

            if (MainConfig.StarterMode == GameStartMode.MultiSocketStarterSlave)
            {
                while (SlaveClient == null)
                {
                    try
                    {
                        SlaveClient = new SlaveClient(MainConfig.MasterStarterMasterLoc, MainConfig.PortNumber);
                    }
                    catch
                    {
                        const string Error = "\nError - Slaves Master Server is not responding.\nPlease Check the server, its endpoint, or your config file.\nWill try again in 20000ms.\n";
                        Logger.WriteLog(Error, LoggerWarringLevel.Danger);
#if !DEBUG
                        DialogResult Result = MessageBox.Show(Error, "Error", MessageBoxButtons.RetryCancel);
                        if (Result == DialogResult.Cancel)
                        {
                            Application.Exit();
                        }
#endif
                        Thread.Sleep(20000);
                    }
                }
            }

            NoIc_GameStarterStopper.ContextMenuStrip = BuildMenu();
            NoIc_GameStarterStopper.Visible          = true;

            Logger.WriteLog($"'Arcade Game Start And Stop Service' has Started with the following parameters:\n\tCardModeMode:{MainConfig.CardModeMode}\n\tServerMode:{MainConfig.ServerMode}\n");
        }
        static void Main(string[] args)
        {
            startTime = DateTime.Now;



            Console.Title           = "[Starting] Game Server";
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(@" _______        _______ _______  ______ _______ _______ _     _");
            Console.WriteLine(@" |_____| |         |    |______ |_____/ |______ |  |  | |     |");
            Console.WriteLine(@" |     | |_____    |    |______ |    \_ |______ |  |  | |_____|");
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine(new string('_', Console.WindowWidth));
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Developed by CodeDragon, DarkRaptor");
            Console.ForegroundColor = ConsoleColor.Gray;

            if (!Config.Read())
            {
                Log.Instance.WriteError("Failed to load the configuration file.");
                Console.ReadKey();
                return;
            }

            ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, "-----------------------Server booted-------------------------");

            if (!Databases.Init())
            {
                Log.Instance.WriteError("Failed to initilize all database connections.");
                Console.ReadKey();
                return;
            }

            if (!GameConfig.Read())
            {
                Log.Instance.WriteError("Failed to load the game configuration");
                Console.ReadKey();
                return;
            }

            if (!Managers.ItemManager.Instance.Load())
            {
                Log.Instance.WriteError("Failed to initilize the item manager.");
                Console.ReadKey();
                return;
            }

            if (!Managers.VehicleManager.Instance.Load())
            {
                Log.Instance.WriteError("Failed to initialize the vehicle Manager.");
                Console.ReadKey();
                return;
            }

            if (!Managers.MapManager.Instance.Load())
            {
                Log.Instance.WriteError("Failed to initilize the map manager.");
                Console.ReadKey();
                return;
            }

            if (!Managers.CouponManager.Instance.Load())
            {
                Log.Instance.WriteError("Failed to initialize the coupon manager.");
                Console.ReadKey();
                return;
            }

            if (!Managers.ClanManager.Instance.Load())
            {
                Log.Instance.WriteError("Failed to initialize the clan manager.");
                Console.ReadKey();
                return;
            }

            // CONNECT TO THE AUTHORIZATION SERVER //
            AuthServer = new ServerClient(Config.AUTH_SERVER_IP, (int)Ports.Internal);
            if (!AuthServer.Connect())
            {
                return;
            }

            if (!new UDPListener((int)Ports.UDP1).Start())
            {
                return;
            }

            if (!new UDPListener((int)Ports.UDP2).Start())
            {
                return;
            }

            //SHOW THE CONFIGURATION RATES

            if (Config.SERVER_DEBUG == 1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("SERVER IS RUNNING IN DEBUG MODE!!!");
            }

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Dinar rate is: " + GameConfig.DinarRate.ToString());
            Console.WriteLine("EXP rate is: " + GameConfig.ExpRate.ToString());
            Console.WriteLine("Bomb time is " + GameConfig.BombTime.ToString());
            Console.WriteLine("Maximum team difference is " + GameConfig.MaxTeamDifference.ToString());
            Console.WriteLine("Maximum room count is " + GameConfig.MaxRoomCount.ToString());
            Console.ForegroundColor = ConsoleColor.Gray;

            ServerLogger.Instance.Append("Server initialiced correctly");

            // Start up the listener :)
            isRunning = (new ServerListener((int)Ports.Game)).Start();

            if (isRunning)
            {
                TimeSpan loadTime = DateTime.Now - startTime;
                Log.Instance.WriteLine(string.Format("Emulator loaded in {0} milliseconds!", loadTime.TotalMilliseconds));
                ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, string.Format("Emulator loaded in {0} milliseconds!", loadTime.TotalMilliseconds));
            }

            startTime = DateTime.Now;
            while (isRunning)
            {
                TimeSpan runTime = DateTime.Now - startTime;
                Console.Title = string.Format("「Game Server」Uptime {0} | Players: {1} | Peak: {2} | Rooms: {3}", runTime.ToString(@"dd\:hh\:mm\:ss"), Managers.UserManager.Instance.Sessions.Values.Count, Managers.UserManager.Instance.Peak, Managers.ChannelManager.Instance.RoomCount);


                if (serverLoops % 5 == 0)
                {
                    Parallel.ForEach(Managers.UserManager.Instance.Sessions.Values, user => {
                        if (user.Authorized)
                        {
                            user.SendPing();
                        }
                    });
                }

                //ping to auth  server
                AuthServer.Send(new Packets.Internal.Ping());

                serverLoops++;

                Thread.Sleep(1000);
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            startTime = DateTime.Now;

            Console.Title           = "「Starting」AlterEmu Game server";
            Console.WindowWidth     = Console.LargestWindowWidth - 25;
            Console.WindowHeight    = Console.LargestWindowHeight - 25;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(@" _______        _______ _______  ______ _______ _______ _     _");
            Console.WriteLine(@" |_____| |         |    |______ |_____/ |______ |  |  | |     |");
            Console.WriteLine(@" |     | |_____    |    |______ |    \_ |______ |  |  | |_____|");
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine(new string('_', Console.WindowWidth));
            Console.WriteLine();

            if (!Config.Read())
            {
                Log.Instance.WriteError("Failed to load the configuration file.");
                Console.ReadKey();
                return;
            }

            if (!Databases.Init())
            {
                Log.Instance.WriteError("Failed to initilize all database connections.");
                Console.ReadKey();
                return;
            }

            if (!Managers.ItemManager.Instance.Load())
            {
                Log.Instance.WriteError("Failed to initilize the item manager.");
                Console.ReadKey();
                return;
            }

            if (!Managers.MapManager.Instance.Load())
            {
                Log.Instance.WriteError("Failed to initilize the map manager.");
                Console.ReadKey();
                return;
            }

            // CONNECT TO THE AUTHORIZATION SERVER //
            AuthServer = new ServerClient(Config.AUTH_SERVER_IP, (int)Ports.Internal);
            if (!AuthServer.Connect())
            {
                return;
            }

            if (!new UDPListener((int)Ports.UDP1).Start())
            {
                return;
            }

            if (!new UDPListener((int)Ports.UDP2).Start())
            {
                return;
            }

            // Start up the listener :)
            isRunning = (new ServerListener((int)Ports.Game)).Start();

            if (isRunning)
            {
                TimeSpan loadTime = DateTime.Now - startTime;
                Log.Instance.WriteLine(string.Format("Emulator loaded in {0} milliseconds!", loadTime.TotalMilliseconds));
            }

            startTime = DateTime.Now;
            while (isRunning)
            {
                TimeSpan runTime = DateTime.Now - startTime;
                Console.Title = string.Format("「AlterEmu-Game」Uptime {0} | Players: {1} | Peak: {2} | Rooms: {3}", runTime.ToString(@"dd\:hh\:mm\:ss"), Managers.UserManager.Instance.Sessions.Values.Count, Managers.UserManager.Instance.Peak, Managers.ChannelManager.Instance.RoomCount);

                if (serverLoops % 5 == 0)
                {
                    Parallel.ForEach(Managers.UserManager.Instance.Sessions.Values, user => {
                        if (user.Authenticated)
                        {
                            user.SendPing();
                        }
                    });
                }

                serverLoops++;

                Thread.Sleep(1000);
            }
        }