Exemple #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");
     }
 }
Exemple #2
0
        public void startPrivateConversation(string withWho)
        {
            appendText(withWho);

            if (notAlreadyOpen(withWho))
            {
                dataTypes objToSend = new dataTypes();
                objToSend.setType(typeof(startPrivate).ToString());

                startPrivate startPrv = new startPrivate();
                startPrv.setWhoStarts(username);
                startPrv.setWithWho(withWho);

                objToSend.setObject(startPrv);

                netServ.sendObjectToServer(objToSend);

                try
                {
                    Thread sf = new Thread(showPrivateWindow);
                    sf.Start(withWho);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Already in a private conversation with " + withWho + ".");
            }
        }
        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");
            }
        }