コード例 #1
0
ファイル: Logger.cs プロジェクト: tuancuongth88/ccms_gcafe
 private static void reconnectSoket()
 {
     //Start Soket Log file
     var OPT = new Quobject.SocketIoClientDotNet.Client.IO.Options();
     OPT.ForceNew = true;
     OPT.Timeout = 3000;
     GlobalSystem.socketLog = IO.Socket(Constant.serverSoketLog, OPT);
     GlobalSystem.socketLog.On(Socket.EVENT_CONNECT, () =>
     {
     });
 }
コード例 #2
0
        public Socket(string UrlNode, Quobject.SocketIoClientDotNet.Client.IO.Options options = null)
        {
            if (options == null)
            {
                options = new Quobject.SocketIoClientDotNet.Client.IO.Options()
                {
                    IgnoreServerCertificateValidation = true,
                    AutoConnect = true,
                    ForceNew    = true
                };
            }

            _socket = Quobject.SocketIoClientDotNet.Client.IO.Socket(UrlNode, options);
        }
コード例 #3
0
        public void startServer()
        {
            try
            {
                var OPT = new Quobject.SocketIoClientDotNet.Client.IO.Options();
                OPT.ForceNew        = true;
                OPT.Timeout         = 3000;
                GlobalSystem.socket = IO.Socket(Constant.serverSoket, OPT);
                GlobalSystem.socket.On(Socket.EVENT_CONNECT, () =>
                {
                });
                GlobalSystem.socket.On("login helper", (data) =>
                {
                    string json    = data.ToString();
                    dynamic result = JObject.Parse(json);
                    string ip      = result.ip;
                    Logger.LogDebugFile("Debug: " + ip + "---------------" + GlobalSystem.ipv4);

                    if (ip == GlobalSystem.ipv4)
                    {
                        countShowformHome++;
                        if (countShowformHome == 1)
                        {
                            Logger.LogDebugFile("-------------------login helper-----------------");
                            Logger.LogDebugFile("chuỗi json trả về: " + json);
                            bool checklogin = processLoginHelper(json);
                            Logger.LogDebugFile("check login soket: " + checklogin);
                            if (checklogin)
                            {
                                if (InvokeRequired)
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        Logger.LogDebugFile("Đếm số lần soket bán lên: " + countShowformHome);
                                        JObject jout = JObject.FromObject(new { status = 1 });
                                        GlobalSystem.socket.Emit("refresh view", jout);
                                        goToHome(json);
                                    }));
                                    return;
                                }
                            }
                            else
                            {
                                JObject jout = JObject.FromObject(new { status = 0, });
                                GlobalSystem.socket.Emit("refresh view", jout);
                            }
                            Logger.LogDebugFile("-------------------End login helper-----------------");
                        }
                    }
                });

                //socket online
                //var socketOnline = IO.Socket(Constant.serverSoketOnline);
                //socketOnline.On(Socket.EVENT_CONNECT, () =>
                //{
                //});
                //socketOnline.On("request app remote login", (data) =>
                //{
                //    string json = data.ToString();
                //    dynamic result = JObject.Parse(json);
                //    string ip = result.ip;
                //    string partner_id = result.partner_id;
                //    string user_name = result.username;
                //    string token =  result.token;
                //    Logger.LogDebugFile("request app remote login Debug: " + ip + "---------------" + GlobalSystem.ipv4);
                //    if (ip == GlobalSystem.ipv4 && partner_id == ClientPartner.partner_id)
                //    {

                //    }
                //});
            }
            catch (Exception e)
            {
                Logger.LogThisLine("startServer: " + e.Message);
                Thread.Sleep(GlobalSystem.sleep);
                startServer();
            }
        }
コード例 #4
0
        public void startServer()
        {
            try
            {
                var OPT = new Quobject.SocketIoClientDotNet.Client.IO.Options();
                OPT.ForceNew        = true;
                OPT.Timeout         = 3000;
                GlobalSystem.socket = IO.Socket(Constant.serverSoket, OPT);
                GlobalSystem.socket.On(Socket.EVENT_CONNECT, () =>
                {
                    Logger.LogDebugFile("-------------EVEN SOKET EMIT ADD USER---------------");
                    Logger.LogDebugFile("add user rooms = clients username ="******"clients", username = GlobalSystem.user.username });
                    GlobalSystem.socket.Emit("add user", jout);
                    Logger.LogDebugFile("-------------END SOKET EMIT ADD USER---------------");
                    if (!string.IsNullOrEmpty(jsonLogin))
                    {
                        dynamic data = JObject.Parse(jsonLogin);
                        if (data.data["listClientInLastLogin"] != null)
                        {
                            String ip       = data.data.listClientInLastLogin[0].ip.ToString();
                            String username = data.data.listClientInLastLogin[0].username.ToString();
                            JObject jout1   = JObject.FromObject(new { ip = ip, type = 1, username = username, message = "Tài khoản này đăng nhập trên máy khác. Máy bạn sẽ bị thoát ra trong vài giây" });
                            GlobalSystem.socket.Emit("other helper", jout1);
                        }
                    }
                });

                // lăng nghe thông báo từ server trả về
                GlobalSystem.socket.On("new message", (data) =>
                {
                    string json    = data.ToString();
                    dynamic result = JObject.Parse(json);
                    Logger.LogDebugFile("-------------EVEN SOKET NEW MESSAGE---------------");
                    Logger.LogDebugFile("conversations server: " + result.message.conversations_id);
                    Logger.LogDebugFile("conversations cliend: " + GlobalSystem.user.conversation_id);
                    if (result.message.conversations_id != null)
                    {
                        int conversation_id = result.message.conversations_id;
                        if (GlobalSystem.user.conversation_id == conversation_id)
                        {
                            string taget = result.target;
                            Logger.LogDebugFile("taget: " + taget);
                            Logger.LogDebugFile("message content: " + result.message.content);
                            if (taget == "4")
                            {
                                string message = result.message.content;
                                if (InvokeRequired)
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        //alert al = new CCMS.view.alert(message, alert.AlertType.info);
                                        //al.TopMost = false;
                                        //al.Show();
                                        alert.Show(Helper.StripTagsRegex(message), alert.AlertType.info);
                                    }));
                                    return;
                                }
                            }
                            //order service
                            if (taget == "3")
                            {
                                Helper.getProfile();
                                calGameHouse();
                                string message = result.message.content;
                                if (InvokeRequired)
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        alert.Show(Helper.StripTagsRegex(message), alert.AlertType.success, false);
                                    }));
                                    return;
                                }
                            }
                            //order service => huy don hang
                            if (taget == "7")
                            {
                                Helper.getProfile();
                                calGameHouse();
                                string message = result.message.content;
                                if (InvokeRequired)
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        alert.Show(Helper.StripTagsRegex(message), alert.AlertType.error);
                                    }));
                                    return;
                                }
                            }
                            //order card success
                            if (taget == "6")
                            {
                                Helper.getProfile();
                                calGameHouse();
                                string message = result.message.content;
                                if (InvokeRequired)
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        alert.Show(Helper.StripTagsRegex(message), alert.AlertType.success);
                                    }));
                                    return;
                                }
                            }
                            //order card success
                            if (taget == "8")
                            {
                                Helper.getProfile();
                                calGameHouse();
                                string message = result.message.content;
                                if (InvokeRequired)
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        alert.Show(Helper.StripTagsRegex(message), alert.AlertType.success);
                                    }));
                                    return;
                                }
                            }
                        }
                    }
                    Logger.LogDebugFile("-------------END NEW MESSAGE---------------");
                });
                // lắng nghe nạp tiền
                GlobalSystem.socket.On("order card success", (data) =>
                {
                    string json    = data.ToString();
                    dynamic result = JObject.Parse(json);
                });

                GlobalSystem.socket.On("order success", (data) =>
                {
                    string json    = data.ToString();
                    dynamic result = JObject.Parse(json);
                });
                GlobalSystem.socket.On("other helper", (data) =>
                {
                    Logger.LogDebugFile("-------------START ORTHER HELPER---------------");
                    string json         = data.ToString();
                    dynamic result      = JObject.Parse(json);
                    string ip           = result.ip;
                    int type            = result.type;
                    String username_log = result.username.ToString();
                    Logger.LogDebugFile("Debug log off: " + ip + "|---------|" + GlobalSystem.ipv4 + "|||  -  ------ username: "******"Debug log off json: " + json);
                    if (ip == GlobalSystem.ipv4 && username_log == GlobalSystem.user.username)
                    {
                        countLogout++;
                        if (countLogout == 1)
                        {
                            Logger.LogDebugFile("Số làn xử lý other helper: " + countLogout);
                            // logout
                            Logger.LogDebugFile("Debug log off Type: " + type);
                            if (type == 1)
                            {
                                if (GlobalSystem.user == null)
                                {
                                    return;
                                }
                                // after we've done all the processing,
                                JObject jout = JObject.FromObject(new { status = 1 });
                                GlobalSystem.socket.Emit("refresh view", jout);

                                if (InvokeRequired)
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        if (result["message"] != null)
                                        {
                                            String message = result.message;
                                            //MessageBox.Show(message);
                                            AutoClosingMessageBox.Show(message, "Thông báo", GlobalSystem.sleep);
                                        }
                                    }));
                                }
                                // send lại server thong tin logout thanh cong
                                GlobalSystem.socket.Disconnect();
                                GlobalSystem.socket.Close();
                                logout();
                                return;
                            }
                            // restart
                            if (type == 2)
                            {
                                if (InvokeRequired)
                                {
                                    // after we've done all the processing,
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        GlobalSystem.socket.Close();
                                        Process.Start("shutdown", "/r /t 10");
                                        Logger.LogThisLine("Tat may tinh trong truong hop restart");
                                        logout();
                                        Environment.Exit(0);
                                    }));
                                    // restart lại máy tính
                                    return;
                                }
                            }
                        }
                    }
                    Logger.LogDebugFile("-------------END ORTHER HELPER---------------");
                });
                GlobalSystem.socket.On("minus money", (data) =>
                {
                    string json    = data.ToString();
                    dynamic result = JObject.Parse(json);
                });
                GlobalSystem.socket.On("end task", (data) =>
                {
                    string json    = data.ToString();
                    dynamic result = JObject.Parse(json);
                    String ip      = result.ip;
                    int id_process = result.task_id;
                    if (GlobalSystem.ipv4.Equals(ip))
                    {
                        lstprocess[id_process].Kill();
                    }
                });
                GlobalSystem.socket.On("load client task", (data) =>
                {
                    string ip = data.ToString();

                    if (GlobalSystem.ipv4.Equals(ip))
                    {
                        getProcess();
                    }
                });

                GlobalSystem.socket.On("client performance", data =>
                {
                    string ip = data.ToString();

                    if (GlobalSystem.ipv4.Equals(ip))
                    {
                        JObject jout = JObject.FromObject(new { cpu = "18%", ram = "25%" });
                        GlobalSystem.socket.Emit("client performance", jout);
                    }
                });

                GlobalSystem.socket.On("load progress task admin", data =>
                {
                    string ip = data.ToString();

                    if (GlobalSystem.ipv4.Equals(ip))
                    {
                        JObject jout = JObject.FromObject(new { cpu = "10%", ram = "25%" });
                        GlobalSystem.socket.Emit("client performance", jout);
                    }
                });
            }
            catch (Exception e)
            {
                Logger.LogThisLine("startServer" + e.Message);
                Task.Delay(5000);
                startServer();
            }
        }
コード例 #5
0
        public void Execute()
        {
            try
            {
                var options = new Quobject.SocketIoClientDotNet.Client.IO.Options
                {
                    AutoConnect  = false,
                    Reconnection = true,
                    Transports   = Quobject.Collections.Immutable.ImmutableList.Create <string>("websocket")
                };

                socket = IO.Socket(AgentProfile.Instance.settingObject["notificationUrl"], options);//ws://192.168.0.67:8089

                socket.On(Socket.EVENT_ERROR, (data) =>
                {
                    Console.WriteLine(data);
                });


                socket.On(Socket.EVENT_CONNECT, (data) =>
                {
                    try
                    {
                        Console.WriteLine(data);
                        //var jsonObject = new JObject { { "token", AgentProfile.Instance.server.token } };
                        //socket.Emit("authenticate", jsonObject);
                        SendAuth();
                    }
                    catch (Exception exception)
                    {
                        Logger.Instance.LogMessage(Logger.LogAppender.DuoDefault, "EVENT_CONNECT", exception, Logger.LogLevel.Error);
                    }
                });


                socket.On("clientdetails", (data) =>
                {
                    Console.WriteLine(data);
                });


                socket.On("authenticated", (data) =>
                {
                    if (OnAuthenticated != null)
                    {
                        OnAuthenticated(data);
                    }
                });

                socket.On("agent_found", (data) =>
                {
                    if (OnAgentFound != null)
                    {
                        OnAgentFound(data);
                    }
                });

                socket.On("agent_suspended", (data) =>
                {
                    Console.WriteLine(data);
                    if (OnAgentSuspended != null)
                    {
                        OnAgentSuspended(data);
                    }
                });

                socket.On(Socket.EVENT_DISCONNECT, (data) =>
                {
                    Console.WriteLine(data);
                });

                socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
                {
                    Console.WriteLine(data);
                });

                socket.On(Socket.EVENT_MESSAGE, (data) =>
                {
                    Console.WriteLine(data);
                    if (OnMessageReceive != null)
                    {
                        OnMessageReceive(data);
                    }
                });

                socket.Connect();
            }
            catch (Exception exception)
            {
                Logger.Instance.LogMessage(Logger.LogAppender.DuoDefault, "SocketConnector", exception, Logger.LogLevel.Error);
            }
        }