예제 #1
0
        static void Main()
        {
            ElasticSearchCommands.Populate();

            ConnectServer c       = new ConnectServer();
            Thread        cServer = new Thread(() => c.StartServer());

            cServer.Start();



            Thread energy_update = new Thread(() => ElasticSearchCommands.UpdateEnergy());

            //Set boolean to true to run bot clients
            bool bot_test = false;

            if (bot_test)
            {
                List <Thread> thread_list = new List <Thread>();

                for (int i = 0; i < 1; i++)
                {
                    thread_list.Add(new Thread(() => ElasticSearchCommands.BotBehaviour(ElasticSearchCommands.CreateBotShip((i + 20).ToString()))));
                    thread_list[i].Start();
                    Thread.Sleep(500);
                }
            }

            energy_update.Start();
            Console.WriteLine("Pass");
        }
예제 #2
0
 public AccountHelper()
 {
     helper     = new HtmlHelper();
     Server     = new ConnectServer();
     appSetting = new AppSettingModel();
     loginValue = ApplicationData.Current.LocalSettings;
 }
예제 #3
0
    public void cerrarAPP()
    {
        ConnectServer connection = new ConnectServer();

        connection.CloseServer();
        Application.Quit();
    }
예제 #4
0
        public int MaxActiveClientCount = 10000; //todo провверить корректность дисконнекта

        public void Start(string path, int port = SessionClient.DefaultPort)
        {
            var rep = Repository.Get;

            rep.SaveFileName = Path.Combine(path, "World.dat");
            rep.Load();

            //общее обслуживание
            rep.Timer.Add(1000, DoWorld);

            //сохранение, если были изменения
            rep.Timer.Add(10000, () =>
            {
                rep.Save(true);
            });

            ActiveClientCount = 0;

            if (LogMessage != null)
            {
                LogMessage("Start server in port " + port.ToString());
            }

            Connect = new ConnectServer();
            Connect.ConnectionAccepted = ConnectionAccepted;
            Connect.Start(null, port);
        }
예제 #5
0
        public PlayReactor?Connect()
        {
            TcpClient client = localPort is int port ? new TcpClient(new IPEndPoint(IPAddress.Any, port)) : new TcpClient();

            console.Output.WriteLine($"Connecting to {ipAddress}:{this.port}...");
            client.Connect(new IPEndPoint(ipAddress, this.port));
            console.Output.WriteLine("Connected!");

            TCPMessageSender messageSender = new TCPMessageSender(client.GetStream());

            messageSender.QueueMessage(new ConnectClient());
            console.Output.WriteLine("Hailing server...");
            messageSender.SendOneMessage();

            TCPMessagePasser messagePasser = new TCPMessagePasser(client.GetStream(), this);

            while (!serverState.HasValue)
            {
                console.Output.WriteLine("Listening for response...");
                messagePasser.ListenAndReactClient();
            }

            ConnectServer ss = serverState.Value;

            if (ss.CanHost)
            {
                return(new PlayReactor(client, ss));
            }
            else
            {
                return(null);
            }
        }
예제 #6
0
파일: Cmdlets.cs 프로젝트: Yevrag35/SQL-SMO
        public void ConnectServerCmdlet()
        {
            var connect = new ConnectServer
            {
                ServerName = "TPSCCM.yevrag35.com"
            };

            Assert.IsTrue(connect.Invoke <object>().Count() == 0);

            Thread.Sleep(2000);

            var disconnect = new DisconnectServer();

            Assert.IsTrue(disconnect.Invoke <object>().Count() == 0);

            Thread.Sleep(500);

            connect.EncryptConnection = true;
            connect.Force             = true;
            Assert.IsTrue(connect.Invoke <object>().Count() == 0);

            Thread.Sleep(2000);

            disconnect.Invoke();
        }
예제 #7
0
        private void ConnectDB()
        {
            while (true)
            {
                ConnectServer server = new ConnectServer();

                DialogResult result = server.ShowDialog();

                if (result == DialogResult.OK)
                {
                    fileUpDate = File.GetLastWriteTime(ReadXML.XmlFileName);
                    try
                    {
                        this.Reconnect();
                        break;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("数据库连接失败,请重新配置数据库连接!\r\n" + ex.ToString());
                    }
                }
                else
                {
                    break;
                }
            }
        }
예제 #8
0
        public void Server_Unknown_Command()
        {
            String test_command = "test";
            String test_User    = "******";
            String result       = ConnectServer.AddCommand(test_command, test_User);

            Assert.AreEqual("Unknown command: (" + test_command + ") \n Please try again.", result);
        }
예제 #9
0
        public void Server_GetHealth_Command()
        {
            String test_command = "GetHealth";
            String test_User    = "******";
            String result       = ConnectServer.AddCommand(test_command, test_User);

            Assert.AreEqual("Current health: 100", result);
        }
예제 #10
0
        public void Server_GetEnergy_Command()
        {
            String test_command = "GetEnergy";
            String test_User    = "******";
            String result       = ConnectServer.AddCommand(test_command, test_User);

            Assert.AreEqual("Current energy: 100", result);
        }
예제 #11
0
 public HtmlHelper()
 {
     Server          = new ConnectServer();
     appSetting      = new AppSettingModel();
     defineEmoticon  = new DefineEmoticon();
     EasClientDvInfo = new EasClientDeviceInformation();
     GetTemplateHTML();
 }
예제 #12
0
        public void Server_AddCommand() //also acts as a test for the exit command
        {
            String test_command = "exit";
            String test_User    = "******";
            String result       = ConnectServer.AddCommand(test_command, test_User);

            Assert.AreEqual("Quitting game!", result);
        }
예제 #13
0
 //关闭当前连接
 public void Close()
 {
     if (m_Client != null)
     {
         m_Client.Close();
         m_Client = null;
     }
 }
예제 #14
0
        public ListStaff()
        {
            InitializeComponent();

            staffController = new StaffController();
            initCommon();
            conn = new ConnectServer(Constants.server, Constants.user, Constants.password);
            initListStaff();
        }
예제 #15
0
        public void SerializeAndDeSerializeConnectServerMessages()
        {
            ConnectServer connect = new ConnectServer(true, playerIntegerSize, 0, 1);

            byte[]        bytes   = Serializer.Serialize(connect, 0);
            ConnectServer message = (ConnectServer)Serializer.DeSerializeClient(bytes, 0);

            Assert.AreEqual(connect, message, "Should be able to serialize and deserialize the connect server message.");
        }
예제 #16
0
 // Use this for initialization
 void Start()
 {
     Q1            = GameObject.Find("Q1").GetComponent <Text>();
     Q2            = GameObject.Find("Q2").GetComponent <Text>();
     Q3            = GameObject.Find("Q3").GetComponent <Text>();
     Q4            = GameObject.Find("Q4").GetComponent <Text>();
     Q5            = GameObject.Find("Q5").GetComponent <Text>();
     result        = GameObject.Find("result");
     connectServer = GameObject.Find("SceneController").GetComponent <ConnectServer>();
 }
예제 #17
0
        public PlayReactor(TcpClient client, ConnectServer ss)
        {
            playerId = ss.PlayerId;

            this.client   = client;
            messagePasser = new TCPMessagePasser(this.client.GetStream(), this);
            messagePasser.PlayerIntegerSize = ss.PlayerIntegerSize;
            messageSender = new TCPMessageSender(this.client.GetStream());
            messageSender.PlayerIntegerSize = ss.PlayerIntegerSize;

            main = new MainComponent();
        }
예제 #18
0
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit = new RaycastHit();

        Transform lastActiveButton = activeButton;

        activeButton = null;
        if (lastActiveButton != null)
        {
            lastActiveButton.GetComponent <Renderer>().material.color = Color.white;
        }

        if (Physics.Raycast(ray, out hit, 100.0f, ButtonLayer))
        {
            if (hit.transform.CompareTag("Button"))
            {
                activeButton = hit.transform;
                activeButton.GetComponent <Renderer>().material.color = new Color(0.0f, 0.378f, 1.0f);
                int _ID = (int)hit.transform.GetComponent <KeyType>().ButtonID;
                if (Input.GetButtonDown("Fire1"))
                {
                    if (_ID < 10)
                    {
                        severIpAddress += _ID.ToString();
                    }
                    else if (_ID == 10)
                    {
                        severIpAddress += ".";
                    }
                    else if (_ID == 11)
                    {
                        if (severIpAddress.Length > 0)
                        {
                            severIpAddress = severIpAddress.Substring(0, severIpAddress.Length - 1);
                        }
                    }
                    else if (_ID == 12)
                    {
                        IPStream _ipWriter = new IPStream();
                        _ipWriter.WriteIP(severIpAddress);
                        ConnectServer.ConnectToServer(severIpAddress);
                    }
                    IpText.GetComponent <TextMesh>().text = severIpAddress;
                    //Debug.Log(severIpAddress);
                }
            }
        }
    }
예제 #19
0
    // Use this for initialization
    void Start()
    {
        otherNetBuffer = new byte[1024];
        recoBuffer     = new byte[1024];

        connectManager = GameObject.FindGameObjectWithTag("CONNECT");

        if (connectManager == null)
        {
            connectManager = (GameObject)Instantiate(Resources.Load("ConnectManager"));
        }
        cs     = connectManager.GetComponent <ConnectServer> ();
        socket = cs.socket;

        tempHeader  = new Header();
        startBuffer = new byte[tempHeader.startSize];
    }
예제 #20
0
        public void Start(string path, int port = SessionClient.DefaultPort)
        {
            if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Settings.json")))
            {
                ServerSettings      = new ServerSettings();
                ServerSettings.Port = port;

                using (StreamWriter file = File.CreateText(Path.Combine(path, "Settings.json")))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Formatting = Formatting.Indented;
                    serializer.Serialize(file, ServerSettings);
                }
            }
            else
            {
                ServerSettings = JsonConvert.DeserializeObject <ServerSettings>(File.ReadAllText(Path.Combine(path, "Settings.json")));
            }

            Loger.PathLog  = path;
            Loger.IsServer = true;

            Loger.Log($"Server starting on port: {ServerSettings.Port}");

            var rep = Repository.Get;

            rep.SaveFileName = Path.Combine(path, "World.dat");
            rep.Load();

            //общее обслуживание
            rep.Timer.Add(1000, DoWorld);

            //сохранение, если были изменения
            rep.Timer.Add(ServerSettings.SaveInterval, () =>
            {
                rep.Save(true);
            });

            ActiveClientCount = 0;

            Connect = new ConnectServer();
            Connect.ConnectionAccepted = ConnectionAccepted;
            Connect.Start(null, ServerSettings.Port);
        }
예제 #21
0
        /// <summary>
        /// 处理连接服务器消息 --注意:此版本已不用这个消息,保留是为了兼容前面的版本
        /// </summary>
        /// <param name="message"></param>
        private void HandleConnectServer(string message)
        {
            //try
            //{
            ConnectServer Data           = (ConnectServer)XmlUtil.Deserialize(typeof(ConnectServer), message);
            string        ZXIT_JSKF_TEST = Data.CommandID;

            if (ZXIT_JSKF_TEST == "ConnectServer")
            {
                string xml = XmlUtil.GetXMlStart() + "<ZXEMC><CommandID>ConnectServerResp</CommandID><ConnectResult>1</ConnectResult><FailtureReason></FailtureReason></ZXEMC>";
                ServerClient.SendMessage(xml);
            }
            else
            {
                string xml = XmlUtil.GetXMlStart() + "<ZXEMC><CommandID>ConnectServerResp</CommandID><ConnectResult>0</ConnectResult><FailtureReason>网络单元连接服务器名称不正确</FailtureReason></ZXEMC>";
                ServerClient.SendMessage(xml);
            }
            //}
            // catch (Exception ex) { LogHelper.WriteLog("" , ex); }
        }
예제 #22
0
        private void connect_server_thread(object player_name)
        {
            ConnectServer conn        = new ConnectServer();
            int           conn_result = conn.connect_server((string)player_name);

            if (conn_result == 1)
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                            (ThreadStart) delegate()
                {
                    connect_message_block.Text = "Player full! Please try later.";
                });
            }
            else if (conn_result == 0)
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                            (ThreadStart) delegate()
                {
                    Start_Interface.Visibility = Visibility.Hidden;
                    Game_Interface.Visibility  = Visibility.Visible;

                    my_id = conn.get_player_id();
                    player_name_blocks[my_id].Text        = user_name_input_box.Text;
                    player_name_blocks[my_id].Foreground  = new SolidColorBrush(Colors.Black);
                    player_score_blocks[my_id].Foreground = new SolidColorBrush(Colors.Black);
                });
                server_socket = conn.get_socket();
                socket_using  = true;
                receive_message_thread.Start();
            }
            else
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                            (ThreadStart) delegate()
                {
                    connect_message_block.Text = "Connect wrong! Please try later.";
                });
            }
        }
예제 #23
0
        public void Start()
        {
            var rep = Repository.Get;

            //общее обслуживание
            rep.Timer.Add(1000, DoWorld);

            //сохранение, если были изменения
            rep.Timer.Add(ServerSettings.SaveInterval, () =>
            {
                rep.Save(true);
            });

            //ServerManager.ServerSettings.AutoSaveStatisticsFile SavePlayerStatisticsFile()

            //ActiveClientCount = 0;

            Connect = new ConnectServer();
            Connect.ConnectionAccepted = ConnectionAccepted;

            Loger.Log($"Server starting on port: {ServerSettings.Port}");
            Connect.Start(null, ServerSettings.Port);
        }
예제 #24
0
        public async void LoginMethod(string userName, string passWord, Boolean save)
        {
            try
            {
                string contentHtml = string.Empty;
                ConnectServer.Login(userName, passWord, ref contentHtml);
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(contentHtml);
                StringReader reader = new StringReader(doc.DocumentNode.OuterHtml);
                string       result = reader.ReadToEnd();
                //Get token.
                string token = Regex.Match(result, "SECURITYTOKEN = \".+\"").Value + Environment.NewLine;
                token = Regex.Match(token, "\".+\"").Value;
                token = token.Remove(0, 1);
                token = token.Remove(token.Length - 1, 1);

                //Get user ID
                string user_id = "";
                if (result.Contains("Welcome, <a href=\"member.php?u="))
                {
                    int startIndex = result.IndexOf("Welcome, <a href=\"member.php?u=") + 31;
                    for (int i = startIndex; i < result.Count(); i++)
                    {
                        if (result[i] == '"')
                        {
                            user_id = result.Substring(startIndex, i - startIndex);
                            break;
                        }
                    }
                }
                //Check Posts
                int checkPost = await helper.GetPosts(int.Parse(user_id));

                appSetting.UserName = userName;
                appSetting.PassWord = passWord;
                appSetting.token    = token;
                appSetting.UserId   = user_id;

                if (save)
                {
                    appSetting.SaveState = "true";
                }
                else
                {
                    loginValue.Values["saveState"] = "false";
                }

                if (checkPost >= 20)
                {
                    appSetting.CheckPosts = "Ok";
                }
                else
                {
                    appSetting.CheckPosts = "NotOk";
                }

                if (token == "guest")
                {
                    showlog();
                    appSetting.UserName = "";
                    appSetting.PassWord = "";
                }
            }
            catch
            { }
        }
예제 #25
0
 public StaffController()
 {
     conn = new ConnectServer(Constants.server, Constants.user, Constants.password);
 }
예제 #26
0
 public MaterialController()
 {
     conn = new ConnectServer(Constants.server, Constants.user, Constants.password);
 }
예제 #27
0
 public void ReceiveConnect(ConnectServer message)
 {
     serverState = message;
 }
예제 #28
0
        static void Main()
        {
            const string applicationName = "TotalSmartCodingSolution"; bool createdNew;

            mutex = new Mutex(true, applicationName, out createdNew);
            if (!createdNew)
            {
                return;
            }                              //app is already running! Exiting the application

            Registries.ProductName = Application.ProductName.ToUpper();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            AutoMapperConfig.SetupMappings();

            //string ApplicationRoleRequired = "false"; //COMMENT ON 11-JUL-2018: NOT USE ApplicationRoleRequired. JUST REMOVE THIS COMMENT ONLY -> TO USE ApplicationRoleRequired (GET ApplicationRoleRequired OPTION FROM CONFIG SETTING BY THE FOLLOWING CommonConfigs.ReadSetting("ApplicationRoleRequired")).
            string ApplicationRoleRequired = CommonConfigs.ReadSetting("ApplicationRoleRequired");

            ApplicationRoles.Required = true; ApplicationRoles.Name = ""; ApplicationRoles.Password = ""; bool applicationRoleRequired = false;
            if (bool.TryParse(ApplicationRoleRequired, out applicationRoleRequired))
            {
                ApplicationRoles.Required = applicationRoleRequired;
            }


            TrialConnects trialConnects      = new TrialConnects();
            DialogResult  trialConnectResult = trialConnects.Connected();

            if (trialConnectResult == DialogResult.Yes)
            {
                Logon logon = new Logon();

                if (logon.ShowDialog() == DialogResult.OK)
                {
                    if (!GlobalEnums.CBPP)
                    {
                        LegalNotice legalNotice = new LegalNotice();
                        legalNotice.ShowDialog(); legalNotice.Dispose();
                    }

                    if (GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Smallpack || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Pail || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Medium4L || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Import || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Drum)
                    {
                        Application.Run(new MasterMDI(GlobalEnums.NmvnTaskID.SmartCoding, new SmartCoding()));
                    }
                    else
                    {
                        if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pickup)
                        {
                            Application.Run(new MasterMDI(GlobalEnums.NmvnTaskID.Pickups, new Pickups()));
                        }
                        else if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.GoodsIssue)
                        {
                            Application.Run(new MasterMDI(GlobalEnums.NmvnTaskID.GoodsIssues, new GoodsIssues()));
                        }
                        else
                        {
                            Application.Run(new MasterMDI());
                        }
                    }
                }
                logon.Dispose();
            }
            else
            if (trialConnectResult == DialogResult.No)
            {
                if (ApplicationRoles.Required)
                {
                    ConnectServer connectServer = new ConnectServer(false);
                    connectServer.ShowDialog(); connectServer.Dispose();
                }
                else
                if (CustomMsgBox.Show(new Form(), "Do you want to specify new application role and password?", "Warning", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    ConnectServer connectServer = new ConnectServer(true);
                    connectServer.ShowDialog(); connectServer.Dispose();
                }
            }
        }
예제 #29
0
 void _init()
 {
     m_Client = new ConnectServer();
 }
예제 #30
0
        public void Start(string path)
        {
            //var jsonFile = Path.Combine(Directory.GetCurrentDirectory(), "Settings.json");
            var jsonFile = Path.Combine(path, "Settings.json");

            if (!File.Exists(jsonFile))
            {
                using (StreamWriter file = File.CreateText(jsonFile))
                {
                    var jsonText = JsonSerializer.Serialize(ServerSettings, new JsonSerializerOptions()
                    {
                        WriteIndented = true
                    });
                    file.WriteLine(jsonText);
                }

                Console.WriteLine("Created Settings.json, server was been stopped");
                Console.WriteLine($"RU: Настройте сервер, заполните {jsonFile}");
                Console.WriteLine("Enter some key");
                Console.ReadKey();
                return;
            }
            else
            {
                try
                {
                    using (var fs = new StreamReader(jsonFile, Encoding.UTF8))
                    {
                        var jsonString = fs.ReadToEnd();
                        ServerSettings = JsonSerializer.Deserialize <ServerSettings>(jsonString);
                    }

                    ServerSettings.WorkingDirectory = path;
                    var results = new List <ValidationResult>();
                    var context = new ValidationContext(ServerSettings);
                    if (!Validator.TryValidateObject(ServerSettings, context, results, true))
                    {
                        foreach (var error in results)
                        {
                            Console.WriteLine(error.ErrorMessage);
                            Loger.Log(error.ErrorMessage);
                        }

                        Console.ReadKey();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine($"RU: Проверьте настройки сервера {jsonFile}");
                    Console.WriteLine("EN: Check Settings.json");
                    Console.ReadKey();
                    return;
                }
            }

            MainHelper.OffAllLog = false;
            Loger.PathLog        = path;
            Loger.IsServer       = true;

            var rep = Repository.Get;

            rep.SaveFileName = Path.Combine(path, "World.dat");
            rep.Load();
            CheckDiscrordUser();
            createFilesDictionary();

            //общее обслуживание
            rep.Timer.Add(1000, DoWorld);

            //сохранение, если были изменения
            rep.Timer.Add(ServerSettings.SaveInterval, () =>
            {
                rep.Save(true);
            });

            //ActiveClientCount = 0;

            Connect = new ConnectServer();
            Connect.ConnectionAccepted = ConnectionAccepted;

            Loger.Log($"Server starting on port: {ServerSettings.Port}");
            Connect.Start(null, ServerSettings.Port);
        }