Exemplo n.º 1
0
        void addMsg(CUser user)
        {
            rtbMessage.SelectionFont  = new Font(new FontFamily(user.fontFamily), user.size);
            rtbMessage.SelectionColor = user._color;
            rtbMessage.AppendText(user.nickname + ":" + user.message + Environment.NewLine);
            rtbMessage.ScrollToCaret();

            txbMessage.Clear();
        }
Exemplo n.º 2
0
 // 서버이동시 동기화할 유저 데이터 구성
 static public void UserDataMove_Start(CUser rc, out ZNet.ArrByte buffer)
 {
     ZNet.CMessage msg = new ZNet.CMessage();
     msg.Write(rc.data.userID);
     msg.Write(rc.data.userName);
     msg.Write(rc.data.money_cash);
     msg.Write(rc.data.money_game);
     msg.Write(rc.data.temp);
     buffer = msg.m_array;
 }
Exemplo n.º 3
0
 void Send(CUser infoUser)
 {
     //input info for user
     this.user.message    = txbMessage.Text;
     this.user._color     = __color;
     this.user.fontFamily = fontFamily;
     this.user.size       = size;
     //Send message to all client
     foreach (Socket item in clientList)
     {
         if (infoUser.getMessage() != string.Empty)
         {
             item.Send(Serialize(infoUser));
         }
     }
 }
Exemplo n.º 4
0
        // 서버이동 완료시 동기화할 유저 데이터 복구
        static public void UserDataMove_Complete(ZNet.ArrByte buffer, out CUser data)
        {
            CUser rc = new CUser();

            ZNet.CMessage msg = new ZNet.CMessage();
            msg.m_array = buffer;

            msg.Read(out rc.data.userID);
            msg.Read(out rc.data.userName);
            msg.Read(out rc.data.money_cash);
            msg.Read(out rc.data.money_game);
            msg.Read(out rc.data.temp);
            data = rc;

            // 서버이동 입장인 경우 즉시 인증완료 상태로 세팅
            data.joined = true;
        }
Exemplo n.º 5
0
        void Connect()
        {
            clientList = new List <Socket>();
            //IP của Server
            this.Text = "Máy chủ[" + IP.ToString() + "]";
            //Chỉ chấp nhận những client kết nối đến IP của server
            IPE = new IPEndPoint(IP, Port);
            //Khởi tạo user server
            user = new CUser("Server", IP);

            server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            server.Bind(IPE);

            Thread Listen = new Thread(() =>
            {
                try
                {
                    while (true)
                    {
                        server.Listen(100);
                        Socket client = server.Accept();
                        //Thong bao co nguoi vao nhom
                        rtbMessage.AppendText(client.RemoteEndPoint.ToString() + " Đã tham gia vào nhóm chat" + Environment.NewLine);
                        //THem vao list client
                        clientList.Add(client);
                        //Them vao list danh sach ket noi
                        listMember.Items.Insert(listMember.Items.Count, client.RemoteEndPoint.ToString());
                        Thread recevie       = new Thread(Receive);
                        recevie.IsBackground = true;
                        recevie.Start(client);
                    }
                }
                catch
                {
                    IPE    = new IPEndPoint(IP, 7777);
                    server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    //server.Bind(IPE);
                }
            });

            Listen.IsBackground = true;
            Listen.Start();
        }