コード例 #1
0
        public void updateClientListToAll()
        {
            displayInMainForm("[Amaranthine Server] Pushing changed Client list to all "+listOfClients.Count.ToString());
            String clients = String.Empty;

            try
            {
                int i = 0;
                string JSONServerResponse = String.Empty;

                ReplyPayload<String> serverResponse = new ReplyPayload<String>();
                serverResponse.Action = Mnemonics.Actions.clientlist;
                serverResponse.source = "AmaranthineServer";
                serverResponse.reply = new String[listOfClients.Count];
                foreach (ClientDetails client in listOfClients)
                {
                    serverResponse.reply[i] = client.userName;
                    i++;
                }
                serverResponse.status = (int)Mnemonics.replyStatus.success;
                JSONServerResponse = JsonConvert.SerializeObject(serverResponse);

                displayInMainForm("[ClientList] " + JSONServerResponse);
                foreach (ClientDetails client in listOfClients)
                {
                    if(client.server.needsUserList)
                        writeToClient(client,JSONServerResponse);
                }
            }
            catch (Exception e)
            {
                displayInMainForm("[Exception] " + e.StackTrace);
            }
            displayInMainForm("[Amaranthine Server]" + clients);
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: debdipto/Amaranthine-Server
        private string getDeviceType(string username)
        {
            String userDeviceType = String.Empty;
            String JSONServerResponse = String.Empty;
            bool usageFlag = false;

            try
            {
                OleDbConnection connect = new OleDbConnection();
                connect.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Optix.accdb;Persist Security Info=False;";
                connect.Open();

                OleDbCommand command = new OleDbCommand();
                command.Connection = connect;
                command.CommandText = "SELECT * FROM Userdetails";

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    String tempUsername = reader["Username"].ToString();
                    if (tempUsername == username)
                    {
                        userDeviceType = reader["devicetype"].ToString();

                        ReplyPayload<String> serverResponseToSender = new ReplyPayload<String>();
                        serverResponseToSender.Action = Mnemonics.Actions.deviceType;
                        serverResponseToSender.source = "AmaranthineServer";
                        serverResponseToSender.status = (int)Mnemonics.replyStatus.success;
                        serverResponseToSender.reply = new String[1];
                        serverResponseToSender.reply[0] = userDeviceType;
                        JSONServerResponse = JsonConvert.SerializeObject(serverResponseToSender);
                        displayInMainForm("[DeviceType] " + JSONServerResponse);

                        usageFlag = true;
                    }
                }

                if (!usageFlag)
                {
                    ReplyPayload<String> serverResponseToSender = new ReplyPayload<String>();
                    serverResponseToSender.Action = Mnemonics.Actions.deviceType;
                    serverResponseToSender.source = "AmaranthineServer";
                    serverResponseToSender.status = (int)Mnemonics.replyStatus.failure;
                    serverResponseToSender.reply = new String[1];
                    serverResponseToSender.reply[0] = "Unable to get deviceType as user not found.";
                    JSONServerResponse = JsonConvert.SerializeObject(serverResponseToSender);
                    writeToClient(JSONServerResponse, false);
                    displayInMainForm("[DeviceType] [Exception] " + JSONServerResponse);
                }
            }
            catch (Exception ex)
            {
                displayInMainForm("[Device Type] [Exception] " + ex.Message);

                displayInMainForm("[Device Type] [Exception] " + ex.StackTrace);

                ReplyPayload<String> serverResponseToSender = new ReplyPayload<String>();
                serverResponseToSender.Action = Mnemonics.Actions.deviceType;
                serverResponseToSender.source = "AmaranthineServer";
                serverResponseToSender.status = (int)Mnemonics.replyStatus.internalFailure;
                serverResponseToSender.reply = new String[1];
                serverResponseToSender.reply[0] = "Unable to get deviceType due to internal exception";
                JSONServerResponse = JsonConvert.SerializeObject(serverResponseToSender);
                writeToClient(JSONServerResponse, false);
            }

            return JSONServerResponse;
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: debdipto/Amaranthine-Server
        public void getClientList()
        {
            try
            {
                int i = 0;
                string JSONServerResponse = String.Empty;

                ReplyPayload<String> serverResponse = new ReplyPayload<String>();
                serverResponse.Action = Mnemonics.Actions.clientlist;
                serverResponse.source = "AmaranthineServer";
                serverResponse.reply = new String[listOfClients.Count];
                foreach (ClientDetails client in listOfClients)
                {
                    serverResponse.reply[i] = client.userName;
                    i++;
                }
                serverResponse.status = (int)Mnemonics.replyStatus.success;
                JSONServerResponse = JsonConvert.SerializeObject(serverResponse);

                displayInMainForm("[ClientList] "+ JSONServerResponse);

                writeToClient(JSONServerResponse, false);
            }
            catch (Exception e)
            {
                displayInMainForm("[ClientList] [Exception] " + e.Message);

                displayInMainForm("[ClientList] [Exception] " + e.StackTrace);

                ReplyPayload<String> serverResponseToSender = new ReplyPayload<String>();
                serverResponseToSender.Action = Mnemonics.Actions.clientlist;
                serverResponseToSender.source = "AmaranthineServer";
                serverResponseToSender.status = (int)Mnemonics.replyStatus.internalFailure;
                serverResponseToSender.reply = new String[1];
                serverResponseToSender.reply[0] = "Unable to get clientlist due to internal Exception";
                String JSONServerResponse = JsonConvert.SerializeObject(serverResponseToSender);
                writeToClient(JSONServerResponse, false);
            }
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: debdipto/Amaranthine-Server
        public void dataFromOthers()
        {
            ReplyPayload<MessageContainer> serverResponse = new ReplyPayload<MessageContainer>();
            serverResponse.source = "AmaranthineServer";
            serverResponse.Action = Mnemonics.Actions.datafromothers;

            serverResponse.reply = new MessageContainer[ClientID.messages.Count];
            int i = 0;
            foreach (MessageContainer messages in ClientID.messages)
            {
                serverResponse.reply[i] = messages;
                i++;
            }

            string JSONServerResponse = String.Empty;

            serverResponse.status = (int)Mnemonics.replyStatus.success;
            JSONServerResponse = JsonConvert.SerializeObject(serverResponse);
            writeToClient(JSONServerResponse, false);

            ClientID.messages.Clear();
        }
コード例 #5
0
ファイル: Server.cs プロジェクト: debdipto/Amaranthine-Server
        private void sendDataNow(dynamic dataFromClient)
        {       
            bool usageFlag = false;
            string JSONServerResponse = String.Empty;
            try
            {
                foreach (ClientDetails client in listOfClients)
                {
                    if (client.userName == (String)dataFromClient.TargetUsername)
                    {
                        usageFlag = true;

                        ReplyPayload<MessageContainer> serverResponse = new ReplyPayload<MessageContainer>();
                        serverResponse.source = (String)dataFromClient.SourceUsername;
                        serverResponse.Action = Mnemonics.Actions.senddatanow;
                        serverResponse.status = (int)Mnemonics.replyStatus.success;
                        serverResponse.reply = new MessageContainer[1];
                        serverResponse.reply[0] = new MessageContainer();
                        serverResponse.reply[0].username = (String)dataFromClient.SourceUsername;
                        serverResponse.reply[0].message = (String)dataFromClient.Message;
                        JSONServerResponse = JsonConvert.SerializeObject(serverResponse);

                        bool replyType= writeToClient(JSONServerResponse, client.clientSocket);
                        if (replyType)
                        {
                            displayInMainForm("[Chatting] " + JSONServerResponse);

                            logChat(userName, userName, client.userName, (String)dataFromClient.Message);

                            ReplyPayload<String> serverResponseToSender = new ReplyPayload<String>();
                            serverResponseToSender.Action = Mnemonics.Actions.serverReply;
                            serverResponseToSender.source = "AmaranthineServer";
                            serverResponseToSender.status = (int)Mnemonics.replyStatus.success;
                            serverResponseToSender.reply = new String[1];
                            serverResponseToSender.reply[0] = "Message sent to client";
                            JSONServerResponse = JsonConvert.SerializeObject(serverResponseToSender);
                            writeToClient(JSONServerResponse, false);
                            displayInMainForm("[Chatting] " + JSONServerResponse);
                        }
                        else
                        {
                            dispatcher.removeClientFromList(client);
                            removeUser(client.label);
                        }
                    }
                }

                if (!usageFlag)
                {
                    ReplyPayload<String> serverResponseToSender = new ReplyPayload<String>();
                    serverResponseToSender.source = "AmaranthineServer";
                    serverResponseToSender.status = (int)Mnemonics.replyStatus.failure;
                    serverResponseToSender.reply = new String[1];
                    serverResponseToSender.reply[0] = "Message not sent to client";
                    JSONServerResponse = JsonConvert.SerializeObject(serverResponseToSender);
                    writeToClient(JSONServerResponse, false);
                    displayInMainForm("[Chatting] [Exception] " + JSONServerResponse);
                }
            }
            catch (Exception e)
            {
                displayInMainForm("[Chatting] [Exception] " + e.Message);

                displayInMainForm("[Chatting] [Exception] " +e.StackTrace);

                ReplyPayload<String> serverResponseToSender = new ReplyPayload<String>();
                serverResponseToSender.Action = Mnemonics.Actions.senddatanow;
                serverResponseToSender.source = "AmaranthineServer";
                serverResponseToSender.status = (int)Mnemonics.replyStatus.internalFailure;
                serverResponseToSender.reply = new String[1];
                serverResponseToSender.reply[0] = "Message not sent to client due to internal Exception";
                JSONServerResponse = JsonConvert.SerializeObject(serverResponseToSender);
                writeToClient(JSONServerResponse, false);
            }
        }