コード例 #1
0
        public void Join(uint hostId, bool directP2P)
        {
            var            encrypted      = Filter.Config.EnableP2PEncryptedMessaging;
            EncryptContext encryptContext = null;

            if (encrypted)
            {
                encryptContext = new EncryptContext(Filter.Config.EncryptedMessageKeyLength);
            }

            var remotePeer = new ServerRemotePeer(this, hostId, directP2P, encryptContext);

            if (!_members.TryAdd(hostId, remotePeer))
            {
                throw new ProudException($"Member {hostId} is already in P2PGroup {HostId}");
            }

            var session = _filter.SessionLookupByHostId.GetValueOrDefault(hostId);

            if (session != null)
            {
                session.P2PGroup = this;

                if (encrypted)
                {
                    session.Send(new P2PGroup_MemberJoinMessage(HostId, hostId, 0, encryptContext.RC4.Key, directP2P));
                }
                else
                {
                    session.Send(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, hostId, 0, directP2P));
                }
            }

            foreach (var member in _members.Values.Where(member => member.HostId != hostId).Cast <ServerRemotePeer>())
            {
                var memberSession = _filter.SessionLookupByHostId.GetValueOrDefault(member.HostId);

                var stateA = new P2PConnectionState(member);
                var stateB = new P2PConnectionState(remotePeer);

                remotePeer.ConnectionStates[member.HostId] = stateA;
                member.ConnectionStates[remotePeer.HostId] = stateB;
                if (encrypted)
                {
                    memberSession?.Send(new P2PGroup_MemberJoinMessage(HostId, hostId, stateB.EventId, encryptContext.RC4.Key, directP2P));
                    session?.Send(new P2PGroup_MemberJoinMessage(HostId, member.HostId, stateA.EventId, member.EncryptContext.RC4.Key, directP2P));
                }
                else
                {
                    memberSession?.Send(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, hostId, stateB.EventId, directP2P));
                    session?.Send(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, member.HostId, stateA.EventId, directP2P));
                }
            }
        }
コード例 #2
0
        public void Join(uint hostId)
        {
            var   encrypted = _server.Configuration.EnableP2PEncryptedMessaging;
            Crypt crypt     = null;

            if (encrypted)
            {
                crypt = new Crypt(_server.Configuration.EncryptedMessageKeyLength,
                                  _server.Configuration.FastEncryptedMessageKeyLength);
            }

            var session    = _server.Sessions[hostId];
            var remotePeer = new RemotePeer(this, session, crypt);

            if (!_members.TryAdd(hostId, remotePeer))
            {
                throw new ProudException($"Member {hostId} is already in P2PGroup {HostId}");
            }

            session.P2PGroup = this;

            if (encrypted)
            {
                session.SendAsync(new P2PGroup_MemberJoinMessage(HostId, hostId, 0, crypt.AES.Key, crypt.RC4.Key, AllowDirectP2P));
            }
            else
            {
                session.SendAsync(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, hostId, 0, AllowDirectP2P));
            }

            foreach (var member in _members.Values.Where(member => member.HostId != hostId).Cast <RemotePeer>())
            {
                var memberSession = _server.Sessions[member.HostId];

                var stateA = new P2PConnectionState(member);
                var stateB = new P2PConnectionState(remotePeer);

                remotePeer.ConnectionStates[member.HostId] = stateA;
                member.ConnectionStates[remotePeer.HostId] = stateB;
                if (encrypted)
                {
                    memberSession.SendAsync(new P2PGroup_MemberJoinMessage(HostId, hostId, stateB.EventId, crypt.AES.Key, crypt.RC4.Key, AllowDirectP2P));
                    session.SendAsync(new P2PGroup_MemberJoinMessage(HostId, member.HostId, stateA.EventId, crypt.AES.Key, member.Crypt.RC4.Key, AllowDirectP2P));
                }
                else
                {
                    memberSession.SendAsync(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, hostId, stateB.EventId, AllowDirectP2P));
                    session.SendAsync(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, member.HostId, stateA.EventId, AllowDirectP2P));
                }
            }
        }
コード例 #3
0
ファイル: P2PGroup.cs プロジェクト: xvanick1/NetspherePirates
        public void Join(uint hostId)
        {
            var   encrypted = _options.EnableP2PEncryptedMessaging;
            Crypt crypt     = null;

            if (encrypted)
            {
                crypt = new Crypt(_options.EncryptedMessageKeyLength);
            }

            var sessionToJoin = _sessionManager.GetSession(hostId);
            IP2PMemberInternal memberToJoin = sessionToJoin;

            if (!_members.TryAdd(hostId, sessionToJoin))
            {
                throw new ProudException($"Member {hostId} is already in P2PGroup {HostId}");
            }

            _log.Debug("Client({HostId}) joined P2PGroup({GroupHostId})", hostId, HostId);
            sessionToJoin.P2PGroup = this;
            memberToJoin.Crypt     = crypt;

            if (encrypted)
            {
                sessionToJoin.Send(new P2PGroup_MemberJoinMessage(HostId, hostId, 0, crypt.AES.Key, AllowDirectP2P));
            }
            else
            {
                sessionToJoin.Send(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, hostId, 0, AllowDirectP2P));
            }

            foreach (var member in _members.Values.Where(member => member.HostId != hostId))
            {
                var stateA = new P2PConnectionState(member);
                var stateB = new P2PConnectionState(sessionToJoin);

                memberToJoin.ConnectionStates[member.HostId] = stateA;
                member.ConnectionStates[memberToJoin.HostId] = stateB;
                if (encrypted)
                {
                    member.Send(new P2PGroup_MemberJoinMessage(HostId, hostId, stateB.EventId, crypt.AES.Key, AllowDirectP2P));
                    sessionToJoin.Send(
                        new P2PGroup_MemberJoinMessage(
                            HostId,
                            member.HostId,
                            stateA.EventId,
                            crypt.AES.Key,
                            AllowDirectP2P
                            )
                        );
                }
                else
                {
                    member.Send(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, hostId, stateB.EventId, AllowDirectP2P));
                    sessionToJoin.Send(
                        new P2PGroup_MemberJoin_UnencryptedMessage(
                            HostId,
                            member.HostId,
                            stateA.EventId,
                            AllowDirectP2P
                            )
                        );
                }
            }

            if (_options.AllowServerAsP2PGroupMember)
            {
                sessionToJoin.Send(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, Constants.HostIdServer, 0, false));
            }

            if (_options.ServerAsP2PGroupMemberHack)
            {
                sessionToJoin.Send(new P2PGroup_MemberJoin_UnencryptedMessage(HostId, Constants.HostIdServerHack, 0, false));
            }
        }