Esempio n. 1
0
        public static void sendmessage(Quobject.SocketIoClientDotNet.Client.Socket socket, string name, string txt)
        {

            socket.Emit("ChatMessage", txt);
            socket.Emit("message:" + txt, "from:" + name);

        }
Esempio n. 2
0
        public static void KetNoi(Quobject.SocketIoClientDotNet.Client.Socket socket, string name)
        {
            //Việc cần làm: Kết nối tới server, thành công đăng kí danh tính MyNameIs, và ConnectToOtherPlayer
            //Đồng thời khởi tạo cái socket.On() để bắt tương ứng các nội dung
            //Bắt ChatMessage
            //Bắt EndGame
            //Bắt NextStepIs
            //Thất bại(Không kết tới server thành công) xuất thông báo và return
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                MessageBox.Show("Connected", "Thông báo", MessageBoxButton.OK);
            });
            socket.On(Socket.EVENT_MESSAGE, (data) =>
            {
                    MessageBox.Show(data.ToString());
            });

            socket.On("ChatMessage", (data) =>
            {
                string s = "You are the first player!";
                turn = data.ToString().Contains(s);
                MessageBox.Show(data.ToString());
                if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!")
                {
                    socket.Emit("MyNameIs", name);
                    socket.Emit("ConnectToOtherPlayer");
                    _name = name;
                }
                else if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() != "Welcome!")
                {
                    _mes = data.ToString();
                }
            });
            socket.On(Socket.EVENT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });
            socket.On("NextStepIs", (data) =>
            {
                var a = JObject.Parse(data.ToString());

                _row = (int)a["row"];
                _col = (int)a["col"];

            });
            socket.On("EndGame", (data) =>
            {
                MessageBox.Show(data.ToString());
            });

        }
Esempio n. 3
0
        public static void KetNoi(Quobject.SocketIoClientDotNet.Client.Socket socket, string name)
        {
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                MessageBox.Show("Connected sucessfully");

            });
           
            socket.On(Socket.EVENT_MESSAGE, (data) =>
            {
               
                MessageBox.Show(data.ToString());
            });
            socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
            {
               
                MessageBox.Show(data.ToString());
            });
            socket.On("ChatMessage", (data) =>
            {
                string k = "You are the first player!";
                bl = data.ToString().Contains(k);
                MessageBox.Show(data.ToString());
                if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!")
                {
                    socket.Emit("MyNameIs", name);
                    socket.Emit("ConnectToOtherPlayer");
                    copy = name;

                }


            });

            socket.On(Socket.EVENT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });
            socket.On("NextStepIs", (data) =>
            {
                var o = JObject.Parse(data.ToString());

                BanCo.rows = (int)o["row"];
                BanCo.columns = (int)o["col"];
            });

        }
Esempio n. 4
0
 public static void GuiToaDo(Quobject.SocketIoClientDotNet.Client.Socket socket, int row, int col)
 {
     //Thực hiện gửi vị trí đánh cho server đầu vào là hàng cột,
     socket.On(Socket.EVENT_ERROR, (data) =>
     {
         MessageBox.Show(data.ToString());
     });
     socket.Emit("MyStepIs", JObject.FromObject(new { row = row, col = col }));
 }
Esempio n. 5
0
        public static void guitoado(Quobject.SocketIoClientDotNet.Client.Socket socket, int row, int col)
        {

            socket.On(Socket.EVENT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });

            socket.Emit("MyStepIs", JObject.FromObject(new { row = row, col = col }));
        }
Esempio n. 6
0
        public static void connected(Quobject.SocketIoClientDotNet.Client.Socket socket, string name)
        {
     
            //socket.On(Socket.EVENT_CONNECT, () =>
            //{
            //    MessageBox.Show("connected", "Thông báo ");

            //});
            socket.On(Socket.EVENT_MESSAGE, (data) =>
            {
                MessageBox.Show(data.ToString());
                
            });
            socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });

            socket.On("ChatMessage", (data) =>
            {
                string s = "You are the first player!";
                turn = data.ToString().Contains(s);
                if (MainWindow.type == 4 && turn == true)
                {
                    Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        MainWindow.txt.Text = data.ToString();
                    }));
                }

                string ten = "";
                var o = JObject.Parse(data.ToString());
                if ((string)o["from"] != null)
                {
                    ten = (string)o["from"];
                }
                else
                {
                    ten = "Server";
                }
                var jobject = data as JToken;
                AppSetting.mes.Mes += ten + "\t\t" + DateTime.Now.ToString() + "\n" + jobject.Value<String>("message") + "\n\t***************************************\n\n";

                if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!")
                {
                    socket.Emit("MyNameIs", name);
                    socket.Emit("ConnectToOtherPlayer");
                    Ten = name;

                }

            });
          
            socket.On(Socket.EVENT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });

            //ham nhan toa do 
            socket.On("NextStepIs", (data) =>
            {
                var o = JObject.Parse(data.ToString());
                if (MainWindow.type == 1)
                {
                    ChessBoard.currPlayer = Player.Onl;
                    //BanCo.currPlayer = o.Value<int>("player");
                    ChessBoard.rows = (int)o["row"];
                    ChessBoard.columns = (int)o["col"];
                }

                
            });
            
        }
Esempio n. 7
0
 public static void changname(Quobject.SocketIoClientDotNet.Client.Socket socket, string name)
 {
     socket.Emit("MyNameIs", name);
     socket.Emit("message:", copy + "is now called" + name);
     copy = name;
 }
Esempio n. 8
0
        public void connected(Quobject.SocketIoClientDotNet.Client.Socket socket, string name)
        {
     
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                MessageBox.Show("connected", "Thông báo ");

            });
            socket.On(Socket.EVENT_MESSAGE, (data) =>
            {
                MessageBox.Show(data.ToString());
                
          
            });
            socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });


            socket.On("ChatMessage", (data) =>
            {
                MessageBox.Show(data.ToString());
                if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!")
                {
                    socket.Emit("MyNameIs", name);
                    socket.Emit("ConnectToOtherPlayer");
                }
                string mes = ((Newtonsoft.Json.Linq.JObject)data)["message"].ToString();
                if (mes.Contains("You are the first player!") == true)
                {
                        activer = 2; 
                }

            });
          
            socket.On(Socket.EVENT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });


            socket.On("NextStepIs", (data) =>
            {

                MessageBox.Show(data.ToString());
                var o = JObject.Parse(data.ToString());
                activer = (int)o["player"];
                row = (int)o["row"];
                column = (int)o["col"];
                MessageBox.Show(row + "  " + column + "   " + activer);
                if (activer == 1)
                {
                   
                        board.play(column, row, activer);
                        activer = 2;
                   
                    
                }

                if (activer == 2)
                {
                    
                        activer = 2;
                    
                    
                }
            });
            
            
        }
Esempio n. 9
0
        public static void connected(Quobject.SocketIoClientDotNet.Client.Socket socket, string name)
        {

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                MessageBox.Show("connected", "Thông báo ");

            });
            socket.On(Socket.EVENT_MESSAGE, (data) =>
            {
                MessageBox.Show(data.ToString());


            });
            socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });
            socket.On("ChatMessage", (data) =>
            {
                string k = "You are the first player!";
                bl = data.ToString().Contains(k);
                var o = JObject.Parse(data.ToString());
                if (connect.bl == true)
                {
                    if (BanCo.Option.WhoPlayWith == Player.Online)
                    {
                        BanCo.currPlayer = Player.Human;
                    }
                    if (BanCo.Option.WhoPlayWith == Player.MayOnline)
                    {
                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            BanCo.currPlayer = Player.Com;

                            MainWindow.txtNguoiMay.Text = data.ToString();
                        }));
                    }

                }


                MainWindow.message = (string)o["message"];
                var jobject = data as JToken;
               NhanMessage.ketnoi.Message += jobject.Value<String>("message") + "  " + DateTime.Now.ToString() + "\n\n";
                if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!")
                {
                    socket.Emit("MyNameIs", name);
                    socket.Emit("ConnectToOtherPlayer");
                    copy = name;
                }
                if ((string)o["from"] != null)
                {
                    MainWindow.name = (string)o["from"];
                }


            });

            socket.On(Socket.EVENT_ERROR, (data) =>
            {
                MessageBox.Show(data.ToString());
            });
            socket.On("NextStepIs", (data) =>
            {
                var o = JObject.Parse(data.ToString());
                if (BanCo.Option.WhoPlayWith == Player.Online)
                {
                    if (((int)o["row"] != connect.rw || (int)o["col"] != connect.cl))
                    {
                        BanCo.rows = (int)o["row"];
                        BanCo.columns = (int)o["col"];
                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            MainWindow.txt.Text = data.ToString();
                        }));
                    }
                }
                if (BanCo.Option.WhoPlayWith == Player.MayOnline)
                {
                    if (((int)o["row"] != connect.rw1 || (int)o["col"] != connect.cl1))
                    {
                        BanCo.rows = (int)o["row"];
                        BanCo.columns = (int)o["col"];
                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            MainWindow.txtMay.Text = data.ToString();
                        }));
                    }
                }

            });

        }
Esempio n. 10
0
 public static void GoiTinNhan(Quobject.SocketIoClientDotNet.Client.Socket socket, string mes, string name)
 {
     socket.Emit("ChatMessage", mes);
     socket.Emit("message:" + mes, "from:" + name);//dòng này làm gìcó? có mà
 } 
Esempio n. 11
0
 public static void DoiTen(Quobject.SocketIoClientDotNet.Client.Socket socket, string name)
 {
     socket.Emit("MyNameIs", name);
     socket.Emit("message:", _name + "is now called" + name);
     _name = name;
 }