Exemplo n.º 1
0
        protected virtual Response callChecked_ListRoomMembers(string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            string roomName = commandSplit[1];

            // get the member list from the upper layer
            IEnumerable <string> memberList;
            Response             res = handle_ListRoomMembers(roomName, out memberList);

            // check result
            if (!res.Success)
            {
                return(res);
            }

            // pack the member list into the response
            string membersString = String.Join(":", memberList);

            return(new Response(true, membersString));
        }
Exemplo n.º 2
0
        protected virtual Response callChecked_Connect(AmTcpClient newConnection, string commandString, out string requestedUsername)
        {
            requestedUsername = "";

            // This function is special and has to do the extra work of splitting and checking the commandstring.
            string[] commandSplit = CpParseUtilities.SplitMessage(commandString, m_stringDelimiter, 2);
            // check it is a "connect" request
            if (commandSplit[0].ToLower() != "connect")
            {
                return(new Response(false, "Expected connection request."));
            }

            // check arguments (should be 2)
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            // check if name has a colon in it (not allowed)
            requestedUsername = commandSplit[1];
            if (requestedUsername.Contains(m_stringDelimiter))
            {
                return(new Response(false, String.Format("Name shall not contain the delimiter character '{0}'.", m_stringDelimiter)));
            }

            // attempt to register the user
            return(handle_Connect(requestedUsername, newConnection));
        }
Exemplo n.º 3
0
        protected virtual Response callChecked_Disconnect(string[] commandSplit, string username)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 1, 1, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            return(handle_Disconnect(username));
        }
Exemplo n.º 4
0
        protected virtual Response receiveEvent_Disconnect_checked(string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 1, 1, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            return(handle_Disconnect());
        }
Exemplo n.º 5
0
        protected virtual Response callChecked_UnsubscribeRoom(string[] commandSplit, string username)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            string roomName = commandSplit[1];

            return(handle_UnsubscribeRoom(roomName, username));
        }
Exemplo n.º 6
0
        protected virtual async Task <Response> callChecked_DeleteRoom(string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            string roomName = commandSplit[1];

            return(await handle_DeleteRoom(roomName));
        }
Exemplo n.º 7
0
        protected virtual Response receiveEvent_RoomDeleted_checked(string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            string roomName = commandSplit[1];

            return(handle_RoomDeleted(roomName));
        }
Exemplo n.º 8
0
        protected virtual async Task <Response> callChecked_MessagePersonalAsync(string[] commandSplit, string fromUsername)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 3, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            CpParseUtilities.RecombineSplitMessage(ref commandSplit, 2);

            string toUsername  = commandSplit[1];
            string messageText = commandSplit[2];

            return(await handle_MessagePersonalAsync(toUsername, fromUsername, messageText));
        }
Exemplo n.º 9
0
        protected virtual Response receiveEvent_MessagePersonal_checked(string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 3, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            CpParseUtilities.RecombineSplitMessage(ref commandSplit, 2);

            string fromUsername = commandSplit[1];
            string messageText  = commandSplit[2];

            return(handle_MessagePersonal(fromUsername, messageText));
        }
Exemplo n.º 10
0
        protected virtual Response callChecked_CreateRoom(string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            string roomName = commandSplit[1];

            Debug.Assert(m_stringDelimiter == ':');
            if (roomName.Contains(m_stringDelimiter))
            {
                return(new Response(false, "Room name shall not contain a colon."));
            }

            return(handle_CreateRoom(roomName));
        }
Exemplo n.º 11
0
        protected override async Task <Tuple <bool, Response> > callChecked_FileUpAsync(FtClient ftClient, string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
            }

            // get filename
            string filename = commandSplit[1];

            // create a file
            using (Stream fileOut = FtFileManager.OpenForWrite(filename, out errMessage))
            {
                if (fileOut == null)
                {
                    return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
                }

                // send ok (ready to receive file)
                bool stillConnected = await SendResponseAsync(ftClient.SerializerAsync, true, "");

                if (!stillConnected)
                {
                    return(new Tuple <bool, Response>(false, null));
                }

                // receive file
                var fileReceiveResult = await FtFileManager.FileReceiveAsync(ftClient.Client, fileOut);

                if (!fileReceiveResult.Item1)
                {
                    return(new Tuple <bool, Response>(fileReceiveResult.Item1, null));
                }

                // send ok (file was received ok)
                return(new Tuple <bool, Response>(true, fileReceiveResult.Item2));
            }
        }
Exemplo n.º 12
0
        protected override async Task <Tuple <bool, Response> > callChecked_FileDownAsync(FtClient ftClient, string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
            }

            // get filename
            string filename = commandSplit[1];

            // open the file
            using (Stream fileIn = FtFileManager.OpenForRead(filename, out errMessage))
            {
                if (fileIn == null)
                {
                    return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
                }
                // send ok (ready to send file)
                bool stillConnected = await SendResponseAsync(ftClient.SerializerAsync, true, "");

                if (!stillConnected)
                {
                    return(new Tuple <bool, Response>(false, null));
                }

                // send file
                stillConnected = await FtFileManager.FileSendAsync(ftClient.Client, fileIn);

                if (!stillConnected)
                {
                    return(new Tuple <bool, Response>(false, null));
                }
            }

            return(new Tuple <bool, Response>(true, new Response(true, "")));
        }
Exemplo n.º 13
0
        protected virtual Response callChecked_ListRooms(string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 1, 1, ref errMessage))
            {
                return(new Response(false, errMessage));
            }

            // get the room list from upper layer
            IEnumerable <string> roomList;
            Response             res = handle_ListRooms(out roomList);

            // the handler actually can't fail, but leave this check in anyway
            if (!res.Success)
            {
                return(res);
            }

            // pack the room list into the response message
            string roomsString = String.Join(":", roomList);

            return(new Response(true, roomsString));
        }