Пример #1
0
        private void OnCreateRoom(SignalingServerMessage ssm)
        {
            IPEndPoint ipe  = (IPEndPoint)ssm.Get(SignalingAttribute.RoomAddress);
            string     tag  = (string)ssm.Get(SignalingAttribute.RoomTag);
            string     name = (string)ssm.Get(SignalingAttribute.RoomName);
            string     des  = (string)ssm.Get(SignalingAttribute.RoomDescription);
            string     key  = ipe.ToString();

            if (tag.Length <= 0)
            {
                Console.WriteLine("Create Room: '[{0}]{1} Failed!'", tag, key);
                ResponseCreateRoom(false);
            }
            lock (_lock)
            {
                int idx = room.FindIndex(x => x.Key == key);

                if (idx != -1)
                {
                    Console.WriteLine("Create Room: '[{0}]{1} Failed!'", tag, key);
                    //room[idx].Update(tag);
                    ResponseCreateRoom(false);
                }
                else
                {
                    Room r = new Room(tag, ipe, des, name);
                    room.Add(r);
                    senderTable.Add(key, sender);
                    clientKey = key;

                    ResponseCreateRoom(true);
                    Console.WriteLine("Create Room: " + r.ToString());
                }
            }
        }
Пример #2
0
        private void OnJoinRoom(SignalingServerMessage ssm)
        {
            IPEndPoint roomName = (IPEndPoint)ssm.Get(SignalingAttribute.RoomAddress);
            string     tag      = (string)ssm.Get(SignalingAttribute.RoomTag);
            string     key      = roomName.ToString();

            lock (_lock)
            {
                Room target = room.Find(x => x.Key == key && x.Tag == tag);
                if (target != null)
                {
                    if (senderTable.ContainsKey(key))
                    {
                        ResponseJoinRoom(true);
                        ResponseConnectionAttemptRequest(key, RemoteEndPoint);
                    }
                    else
                    {
                        ResponseJoinRoom(false);
                    }
                    Console.WriteLine("Peer '{0}' Join Room: '{1}'", RemoteEndPoint.ToString(), key);
                }
                else
                {
                    Console.WriteLine("Peer '{0}' Join Room: '{1}' Failed", RemoteEndPoint.ToString(), key);
                }
            }
        }
Пример #3
0
 private void OnGetRoomList(SignalingServerMessage ssm)
 {
     ResponseGetRoomList((string)ssm.Get(SignalingAttribute.RoomTag));
 }
Пример #4
0
        private void OnCloseRoom(SignalingServerMessage ssm)
        {
            IPEndPoint ipe = (IPEndPoint)ssm.Get(SignalingAttribute.RoomAddress);

            CloseRoom(ipe.ToString());
        }