예제 #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            Message message = new Message(NetManager.me, sendText.Text.ToString());
            clsSend clsSend = new clsSend(message);
            Package package = new Package((uint)Protocol.SEND, clsSend.ToBytes());

            NetManager.toServer.Enqueue(package);
            sendText.Text = "";
        }
예제 #2
0
        private void mainLoop_Tick(object sender, EventArgs e)
        {
            if (NetManager.toClient.Count != 0)
            {
                Package package = NetManager.toClient.Dequeue();
                switch (package.protocol)
                {
                case (uint)Protocol.SECRET:
                    clsSecret clsecret = new clsSecret();
                    clsecret = clsecret.FromBytes(package.data);
                    User fromUser = new User();

                    if (clsecret.forUid != NetManager.me.uid)
                    {
                        foreach (User getUser in NetManager.onlineUser.Values)
                        {
                            if (getUser.uid == clsecret.forUid)
                            {
                                fromUser = getUser;
                                break;
                            }
                        }
                    }
                    else
                    {
                        fromUser = NetManager.me;
                    }

                    writeline("[" + clsecret.message.hour + ":" + clsecret.message.min + "] "
                              + clsecret.message.user.name + " send DM to " + fromUser.name + ":\n"
                              + clsecret.message.message + "\n");
                    break;

                case (uint)Protocol.SEND:
                    clsSend clsSend = new clsSend();
                    clsSend = clsSend.FromBytes(package.data);
                    writeline("[" + clsSend.message.hour + ":" + clsSend.message.min + "] " + clsSend.message.user.name + ":\n"
                              + clsSend.message.message + "\n");
                    break;

                case (uint)Protocol.ADDUSER:
                    clsChangeUser addUser = new clsChangeUser(0, "");
                    addUser = addUser.FromBytes(package.data);
                    User user = new User()
                    {
                        uid = addUser.uid, name = addUser.userName
                    };
                    if (!NetManager.onlineUser.ContainsKey(user.uid) && user.uid != NetManager.me.uid)
                    {
                        NetManager.onlineUser.Add(user.uid, user);
                        userList.Items.Add(user.name);
                    }
                    break;

                case (uint)Protocol.KILLUSER:
                    clsChangeUser killUser = new clsChangeUser(0, "");
                    addUser = killUser.FromBytes(package.data);
                    User kUser = new User()
                    {
                        uid = addUser.uid, name = addUser.userName
                    };
                    if (NetManager.onlineUser.ContainsKey(kUser.uid))
                    {
                        NetManager.onlineUser.Remove(kUser.uid);
                        userList.Items.Remove(kUser.name);
                    }
                    break;
                }
            }
        }