示例#1
0
        public static void StopClient()
        {
            if (!IsClient)
            {
                Main.Log("Client is not running...");
                return;
            }

            Client.Shutdown("The user has disconnected from the server. Bye!");
            Client = null;
        }
示例#2
0
        public static void StartClient()
        {
            if (IsClient)
            {
                Main.Log("Client is already started, cannot start a new one.");
                return;
            }

            var config = new NetPeerConfiguration(APP_ID);

            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

            Client = new CClient(null, config);
            Client.Start();

            Main.Log("Started client...");
        }
示例#3
0
文件: CClient.cs 项目: hnjm/CChat2
        public static void ProcessData(DataType type, NetIncomingMessage msg, CClient c)
        {
            //Main.Log("Got data of type " + type + ", message is " + msg + ", size " + msg.LengthBytes);
            switch (type)
            {
            case DataType.AUDIO:
                // Play this audio.

                int id = msg.ReadInt32();
                int bc = msg.ReadInt32();
                msg.ReadBytes(bc, out buffer);

                Audio.QueuePlay(id, buffer, bc);
                break;

            case DataType.MUTED:
                bool muted = msg.ReadBoolean();
                if (muted)
                {
                    MessageBox.Show("You have been muted by the server owner. Nobody can hear you.", "Muted", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("You have been un-muted by the server owner. Welcome back!", "Un-Muted", MessageBoxButtons.OK);
                }
                break;

            case DataType.NAME:
                int count = msg.ReadInt32();
                Main.Log("Recieving " + count + " names.");
                for (int i = 0; i < count; i++)
                {
                    bool   add  = msg.ReadBoolean();
                    string name = msg.ReadString();
                    if (add)
                    {
                        Main.AddUser(name);
                    }
                    else
                    {
                        Main.RemoveUser(name);
                    }
                }
                break;
            }
        }
示例#4
0
 public static void UponClientDisconnected()
 {
     Client = null;
     Audio.ClearAll();
     Main.UponDisconnected();
 }