Пример #1
0
    public SocketAction GetRPCs()
    {
        Dictionary <string, object> parameters = new Dictionary <string, object>();

        SocketAction action = this.action("getRPCs", parameters);

        return(action);
    }
Пример #2
0
    protected SocketAction action(string actionName, Dictionary <string, object> parameters)
    {
        string payload = DictionarySerializer.ToJSON(parameters);

        SocketAction action = new SocketAction(this, actionName, payload);

        return(action);
    }
Пример #3
0
        public void GetAllUserConversations(string uid)
        {
            var content = new SocketAction {
                Route   = "conversation.get.all",
                Payload = new { uid }
            };

            Emit(ActionRoute, content);
        }
Пример #4
0
 void handleError(bool needClose, SocketAction action, string msg)
 {
     Log.D(string.Format("{0},{1},{2}", needClose, action, msg), Log.Tag.Net);
     if (needClose)
     {
         closeSocket();
     }
     mSocketState = SocketState.Error;
 }
Пример #5
0
        public void GetAllUsers()
        {
            var content = new SocketAction
            {
                Route   = "user.get.all",
                Payload = new { }
            };

            Emit(ActionRoute, content);
        }
Пример #6
0
    public SocketAction JoinGame(string playerName)
    {
        Dictionary <string, object> parameters = new Dictionary <string, object>();

        parameters["playerName"] = playerName;

        SocketAction action = this.rpcAction(RPCName.JoinGame, parameters);

        return(action);
    }
Пример #7
0
        public static void AddVirtualPlayer(string gameID)
        {
            var content = new SocketAction
            {
                Route   = "game.patch.addVirtual",
                Payload = new { _id = gameID }
            };

            WebSocket.Instance.Emit("action", content);
        }
Пример #8
0
        public void JoinGame(string uid, string gid)
        {
            var content = new SocketAction
            {
                Route   = "game.patch.join",
                Payload = new { _id = gid, uid }
            };

            Emit(ActionRoute, content);
        }
Пример #9
0
        public void GetActiveGames()
        {
            var content = new SocketAction
            {
                Route   = "game.get.active",
                Payload = new { }
            };

            Emit(ActionRoute, content);
        }
Пример #10
0
        public void CreateNewGame(string uid)
        {
            var content = new SocketAction
            {
                Route   = "game.post.create",
                Payload = new { uid }
            };

            Emit(ActionRoute, content);
        }
Пример #11
0
    public SocketAction Move(int direction)
    {
        Dictionary <string, object> parameters = new Dictionary <string, object>();

        parameters["direction"] = direction;

        SocketAction action = this.rpcAction(RPCName.Move, parameters);

        return(action);
    }
Пример #12
0
        /*
         * Send event to the server
         */

        public void GetAllConversations()
        {
            var content = new SocketAction
            {
                Route   = "conversation.get.search",
                Payload = new { }
            };

            Emit(ActionRoute, content);
        }
Пример #13
0
        public void CreateStroke(Path path)
        {
            var content = new SocketAction
            {
                Route   = "canvas.patch.stroke",
                Payload = path
            };

            Emit(ActionRoute, content);
        }
Пример #14
0
        public static void LeaveGame(string gid, string uid)
        {
            var content = new SocketAction
            {
                Route   = "game.patch.quit",
                Payload = new { _id = gid, uid }
            };

            WebSocket.Instance.Emit("action", content);
        }
Пример #15
0
        public void GetConversationMessages(string cid)
        {
            var content = new SocketAction
            {
                Route   = "message.get.all",
                Payload = new { cid }
            };

            Emit(ActionRoute, content);
        }
Пример #16
0
        public void GetAllConnectedUsers()
        {
            var content = new SocketAction
            {
                Route   = "user.get.online",
                Payload = { }
            };

            Emit(ActionRoute, content);
        }
Пример #17
0
        public void CreateConversation(string[] uids, string convName)
        {
            var content = new SocketAction
            {
                Route   = "conversation.post.create",
                Payload = new { uids, convName }
            };

            Emit(ActionRoute, content);
        }
Пример #18
0
        public void GetConversation(string cid)
        {
            var content = new SocketAction
            {
                Route   = "conversation.get.one",
                Payload = new { cid }
            };

            Emit(ActionRoute, content);
        }
Пример #19
0
    public SocketAction JoinRoom(string roomID)
    {
        Dictionary <string, object> parameters = new Dictionary <string, object>();

        parameters["roomId"] = roomID;

        SocketAction action = this.action("joinRoom", parameters);

        return(action);
    }
Пример #20
0
        public void AddSocket(Socket socket, Action read, Action write, Action error)
        {
            SocketAction action = new SocketAction();

            action.RWE[0] = read;
            action.RWE[1] = write;
            action.RWE[2] = error;

            _pendingAdd.Add(new object[] { socket, action });
        }
Пример #21
0
 void OnComplete(TcpClient client, SocketAction action, string msg)
 {
     lock (_lockObj)
     {
         SocketEvent se = new SocketEvent()
         {
             _action = action,
             _msg    = msg,
         };
         _socketEventList.Add(se);
     }
 }
Пример #22
0
 void OnComplete(SocketAsyncEventArgs args, SocketAction action)
 {
     try
     {
         Completed?.Invoke(args, action);
     }
     catch (Exception e)
     {
         Debug.LogError($"Server OnComplete() Exception - {e}");
         throw;
     }
 }
Пример #23
0
        public void AddUserToConversation(string cid, string uid)
        {
            var content = new SocketAction
            {
                Route   = "conversation.patch.addUser",
                Payload = new {
                    cid,
                    uid
                }
            };

            Emit(ActionRoute, content);
        }
Пример #24
0
    protected SocketAction rpcAction(string rpcName, Dictionary <string, object> parameters)
    {
        Dictionary <string, object> rpcParameters = new Dictionary <string, object>();

        rpcParameters["rpcName"]    = rpcName;
        rpcParameters["parameters"] = parameters;

        string payload = DictionarySerializer.ToJSON(rpcParameters);

        SocketAction action = new SocketAction(this, "rpc", payload);

        return(action);
    }
Пример #25
0
        public void RefereshUser()
        {
            if (isConnected && AppContext.AppContextSingleton.Instance.AppContext?.CurrentConnectedUser != null)
            {
                var content = new SocketAction
                {
                    Route   = "user.get.one",
                    Payload = new { uid = AppContext.AppContextSingleton.Instance.AppContext?.CurrentConnectedUser.UID }
                };

                Emit(ActionRoute, content);
            }
        }
Пример #26
0
        public void CreateCanvas(List <string> uids)
        {
            var content = new SocketAction
            {
                Route   = "canvas.post.create",
                Payload = new
                {
                    uids,
                }
            };

            Emit(ActionRoute, content);
        }
 public virtual void OnComplete(TcpClient client, SocketAction action, string msg)
 {
     if (Completed == null)
     {
         Log("AsynSocketClient OnComplete Error - Completed() function not found!");
     }
     Completed?.Invoke(client, action, msg);
     if (action == SocketAction.Connect)
     {
         // 接收数据
         ThreadPool.QueueUserWorkItem(x =>
         {
             //while (!isStopWork) // 原始代码这里写错了。。。这里会导致几秒钟之内内存占用超过10G
             {
                 try
                 {
                     ReceiveAsync();
                     Log("AsynsocketClient OnComplete connect - " + msg);
                     //Thread.Sleep(20);
                 }
                 catch (Exception ex)
                 {
                     Stop();
                     string err = $"AsynsocketClient OnComplete Exception (Connect) - {ex}";
                     OnComplete(client, SocketAction.Error, err);
                 }
             }
         });
     }
     else if (action == SocketAction.Send)
     {
     }
     else if (action == SocketAction.Receive)
     {
     }
     else if (action == SocketAction.Close)
     {
         try
         {
             Log("Socket closed.");
             this.Received = null;
             tcpClient.Close();
         }
         catch (Exception e)
         {
             string err = $"AsynSocketClient OnComplete Exception (Close) - {e}";
             OnComplete(client, SocketAction.Error, err);
         }
     }
 }
Пример #28
0
        public void InviteUserToConversation(string cid, string uid)
        {
            var content = new SocketAction
            {
                Route   = "conversation.post.invite",
                Payload = new
                {
                    cid,
                    uid
                }
            };

            Emit(ActionRoute, content);
        }
    void OnComplete(SocketAction action, string msg)
    {
        switch (action)
        {
        case SocketAction.Connect:
        {
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Success);
            // 登录到RoomServer
            PlayerEnter enter = new PlayerEnter();
            if (ClientManager.Instance != null)
            {
                enter.Account = ClientManager.Instance.Player.Account;
                enter.TokenId = ClientManager.Instance.Player.TokenId;
            }
            else
            {
                enter.Account = "Footman3";
                enter.TokenId = 123456;
                //enter.TokenId = 1234561;
            }
            CurrentPlayer.Init(enter.Account, enter.TokenId);
            SendMsg(ROOM.PlayerEnter, enter.ToByteArray());
            StartHeartBeat();     // 开始心跳
            Log(msg);
        }
        break;

        case SocketAction.Send:
            break;

        case SocketAction.Receive:
            break;

        case SocketAction.Close:
            StopHeartBeat();
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            UIManager.Instance.MessageBox("错误", msg, (int)PanelMessageBox.BUTTON.OK, OnClickMessageBox);
            Debug.LogWarning(msg);
            break;

        case SocketAction.Error:
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            UIManager.Instance.MessageBox("错误", msg, (int)PanelMessageBox.BUTTON.OK, OnClickMessageBox);
            Debug.LogWarning(msg);
            break;
        }
    }
Пример #30
0
        public void CreateGameImage(GameImage gameImage)
        {
            var content = new SocketAction
            {
                Route   = "gameImage.post.create",
                Payload = new {
                    hints        = gameImage.Hints,
                    word         = gameImage.Word,
                    lang         = gameImage.WordLanguage,
                    difficulty   = gameImage.Difficulty,
                    canvas       = gameImage.Canvas,
                    drawing_mode = gameImage.DrawingMode
                }
            };

            Emit(ActionRoute, content);
        }