Exemplo n.º 1
0
        private static GAISWriter HandleVideoEnd(GAISReader gr)
        {
            GAISWriter gw = new GAISWriter();

            gw.Write((Int32)OPCODE.VIDEO_END);
            gw.Write(gr.ReadString());
            return(gw);
        }
Exemplo n.º 2
0
        private void startFirst()
        {
            while (!connected)
            {
                try
                {
                    if (client.Available > 0)
                    {
                        gr = new GAISReader(client.GetStream());

                        Int32 id = gr.ReadInt32();
                        nickName = gr.ReadString();

                        foreach (ConnectionInfo c in Server.connections)
                        {
                            if (c.nickName == nickName)
                            {
                                GAISWriter gw = new GAISWriter();
                                gw.Write((Int32)OPCODE.RESPONSE);
                                gw.Write((Int32)RESPONSE.NICKNAME_TAKEN);
                                GAISWriter gwSend = new GAISWriter(client.GetStream());
                                gwSend.Write(gw.ToArray());
                                gwSend.Flush();
                                return;
                            }
                        }
                        ConnectionInfo ci = new ConnectionInfo();
                        ci.nickName = nickName;
                        ci.cl       = client;
                        Server.connections.Add(ci);

                        //create a new thread for this user
                        chatThread = new Thread(new ThreadStart(Run));
                        //start the thread
                        chatThread.Start();

                        connected = true;
                    }
                }
                catch
                {
                    client.Close();
                    connected = true;
                }

                Thread.Sleep(100);
            }
        }
Exemplo n.º 3
0
        private static GAISWriter HandleVideoUpdate(GAISReader gr)
        {
            GAISWriter gw = new GAISWriter();

            gw.Write((Int32)OPCODE.VIDEO_UPDATE);
            gw.Write(gr.ReadString());
            Int32 size = gr.ReadInt32();

            Byte[] arr = gr.ReadBytes(size);

            if (arr.Length > 0)
            {
                gw.Write(size);
                gw.Write(arr);
                return(gw);
            }

            return(null);
        }
Exemplo n.º 4
0
        public static void SendMsgToAll(String nickName, GAISReader gr)
        {
            List <ConnectionInfo> ToRemove = new List <ConnectionInfo>();

            GAISWriter gw = HandleReader(gr);

            foreach (ConnectionInfo c in connections)
            {
                if (c.nickName == nickName)
                {
                    if (gw == null)
                    {
                        ToRemove.Add(c);
                    }
                    else
                    {
                        continue;
                    }
                }
                if (gw != null)
                {
                    try
                    {
                        GAISWriter sendGW = new GAISWriter(c.cl.GetStream());
                        sendGW.Write(gw.ToArray());
                        sendGW.Flush();
                    }
                    catch
                    {
                        ToRemove.Add(c);
                    }
                }
            }

            foreach (ConnectionInfo c in ToRemove)
            {
                connections.Remove(c);
            }

            ToRemove.Clear();
        }
Exemplo n.º 5
0
 public void Write(GAISWriter ww)
 {
     this.Write(ww.ToArray());
 }