Exemplo n.º 1
0
 private void parseObject(dataTypes objReceived)
 {
     if (objReceived.objectType.Equals(typeof(messageToEveryone).ToString()))
     {
         messageToEveryone msg = (messageToEveryone)objReceived.myObject;
         clientMW.appendText("[" + msg.whoAmI + "] " + msg.message);
     }
     else if (objReceived.objectType.Equals(typeof(userList).ToString()))
     {
         userList onlineClients = (userList)objReceived.myObject;
         clientMW.appendUsers(onlineClients.users);
     }
     else if (objReceived.objectType.Equals(typeof(startPrivate).ToString()))
     {
         startPrivate startPRV = (startPrivate)objReceived.myObject;
         clientMW.startPrivateConversationByServer(startPRV.whoStarts);
     }
     else if (objReceived.objectType.Equals(typeof(privateMessage).ToString()))
     {
         privateMessage prvMsg = (privateMessage)objReceived.myObject;
         clientMW.pushPrivateToWindow(prvMsg);
     }
     else if (objReceived.objectType.Equals(typeof(closePrivate).ToString()))
     {
         closePrivate closePrv = (closePrivate)objReceived.myObject;
         clientMW.closePrivate(closePrv);
     }
     else
     {
         throw new Exception("Unsupported object type");
     }
 }
Exemplo n.º 2
0
        private void parseObject(dataTypes objReceived, Socket m_socWorker)
        {
            if (objReceived.objectType.Equals(typeof(loginInfo).ToString()))
            {
                loginInfo clientInfo = (loginInfo)objReceived.myObject;
                bool      result     = DS.isClientAuthorized((loginInfo)objReceived.myObject);
                if (result)
                {
                    serverMW.appendDebugOutput("New client connecterd : " + clientInfo.username);
                }

                for (int i = 0; i < clients.Count; i++)
                {
                    if (clients[i].getSocket() == m_socWorker)
                    {
                        clients[i].setName(clientInfo.username);
                    }
                }

                userList connectedUsers = new userList();
                for (int index = 0; index < clients.Count; index++)
                {
                    connectedUsers.users.Add(clients[index].getUserName());
                }

                STCB.sendUserlistToClients(connectedUsers);
            }
            else if (objReceived.objectType.Equals(typeof(messageToEveryone).ToString()))
            {
                messageToEveryone msg = (messageToEveryone)objReceived.myObject;
                STCB.sendMsgToAllClients(msg);
            }
            else if (objReceived.objectType.Equals(typeof(startPrivate).ToString()))
            {
                startPrivate startPRV = (startPrivate)objReceived.myObject;
                STCB.sendMsgToClient(startPRV.withWho, objReceived);
            }
            else if (objReceived.objectType.Equals(typeof(privateMessage).ToString()))
            {
                privateMessage prvMsg = (privateMessage)objReceived.myObject;
                STCB.sendMsgToClient(prvMsg.toWho, objReceived);
            }
            else if (objReceived.objectType.Equals(typeof(closePrivate).ToString()))
            {
                closePrivate closePrv = (closePrivate)objReceived.myObject;
                STCB.sendMsgToClient(closePrv.toWho, objReceived);
            }
            else
            {
                throw new Exception("Unsupported object type");
            }
        }
Exemplo n.º 3
0
        private void sendBTN_Click(object sender, EventArgs e)
        {
            privateMessage prvMsg = new privateMessage();

            prvMsg.setWhoSent(clientMW.username);
            prvMsg.setToWho(withWho);
            prvMsg.setMessage(msgToSend.Text.Trim());

            appendText("[" + clientMW.username + "] " + prvMsg.message);

            msgToSend.Clear();

            dataTypes objToSend = new dataTypes();

            objToSend.setType(typeof(privateMessage).ToString());
            objToSend.setObject(prvMsg);

            netServ.sendObjectToServer(objToSend);
        }
Exemplo n.º 4
0
        internal void pushPrivateToWindow(privateMessage prvMsg)
        {
            privateConversation thisConv = getWindowByUser(prvMsg.whoSent);

            thisConv.appendText("[" + prvMsg.whoSent + "] " + prvMsg.message);
        }