Exemple #1
0
        public void Connect(IPAddress address)
        {
            NetworkComms.RemoveGlobalConnectionCloseHandler(HandleConnectionClosed);

            NetworkComms.Shutdown();

            connectionInfo = new ConnectionInfo(address.ToString(), port);

            if (!packetsAppended)
            {
                NetworkComms.AppendGlobalIncomingPacketHandler <Custom>("Custom", ReceiveCustomPacket);
                NetworkComms.AppendGlobalIncomingPacketHandler <int>(PacketName.ReSessionVerificationResult.ToString(), SessionVerificationResultReceived);
                NetworkComms.AppendGlobalIncomingPacketHandler <string>(PacketName.ReSessionId.ToString(), SessionIdReceived);
                NetworkComms.AppendGlobalIncomingPacketHandler <int>(PacketName.ReLoginResult.ToString(), ReceiveLoginResult);
                NetworkComms.AppendGlobalIncomingPacketHandler <ModuleList>(PacketName.ReModuleList.ToString(), ModuleList);
                NetworkComms.AppendGlobalIncomingPacketHandler <AppFileData>(PacketName.ReAppFile.ToString(), AppFile);
                NetworkComms.AppendGlobalIncomingPacketHandler <GroupList>(PacketName.ReUserGroupList.ToString(), GroupListReceived);
                NetworkComms.AppendGlobalIncomingPacketHandler <int>(PacketName.ReUnauthorized.ToString(), UnAuthorizedReceived);

                packetsAppended = true;
            }

            NetworkComms.AppendGlobalConnectionCloseHandler(HandleConnectionClosed);

            NetworkComms.DefaultSendReceiveOptions = new SendReceiveOptions(DPSManager.GetDataSerializer <ProtobufSerializer>(),
                                                                            NetworkComms.DefaultSendReceiveOptions.DataProcessors, NetworkComms.DefaultSendReceiveOptions.Options);
        }
Exemple #2
0
        private void HandleConnectionShutdown(Connection connection)
        {
            if (connection == null)
            {
                return;
            }

            var remoteEndPoint = (IPEndPoint)connection.ConnectionInfo.RemoteEndPoint;

            if (remoteEndPoint.Port == _serverConfig.P2P_Port)
            {
                ServerMessageReceivedAction("Disconnected with P2P server");
                DisposeConnection(connection);
            }
            else if (remoteEndPoint.Port == _serverConfig.Port)
            {
                ServerMessageReceivedAction("Disconnected with Main server");
                DisposeConnection(connection);
            }
            else
            {
                _udpTraversal.CleanUp();

                P2PMessageReceivedAction("P2P connection is disconnected");
                DisposeConnection(connection);
            }

            if (_mainConnection == null)
            {
                NetworkComms.RemoveGlobalConnectionCloseHandler(HandleConnectionShutdown);
            }
        }
Exemple #3
0
        public void Start()
        {
            if (!ResolveDns())
            {
                return;
            }

            //_serverConfig.IP = "127.0.0.1";
            ServerMessageReceivedAction("Start connection to Main server");

            try
            {
                _mainConnection = TCPConnection.GetConnection(new ConnectionInfo(_serverConfig.IP, _serverConfig.Port));
                if (_mainConnection.ConnectionInfo.ConnectionState == ConnectionState.Established)
                {
                    _udpTraversal = new UDPTraversal(_serverConfig.IP, _serverConfig.P2P_Port, UDPP2PConnected);

                    //global
                    NetworkComms.AppendGlobalConnectionCloseHandler(HandleConnectionShutdown);

                    //UDP
                    NetworkComms.AppendGlobalIncomingPacketHandler <string>(PacketType.REQ_P2PMessage, HandleP2PMessage);
                    NetworkComms.AppendGlobalIncomingPacketHandler <Screenshot>(PacketType.REQ_P2PScreenshot, HandleP2PScreenshot);

                    //TCP
                    _mainConnection.AppendIncomingPacketHandler <ClientInfo[]>(PacketType.REQ_OnlineClientInfos, HandleOnlineClientInfos);
                    _mainConnection.AppendIncomingPacketHandler <string>(PacketType.REQ_NATInfo, HandleNATInfo);

                    _mainConnection.AppendIncomingPacketHandler <P2PClient>(PacketType.REQ_UDPP2PRequest, HandleUDPP2PRequest);

                    SendLocalClientInfo();
                }
                else
                {
                    ServerMessageReceivedAction("Failed connect to Main server");

                    NetworkComms.RemoveGlobalConnectionCloseHandler(HandleConnectionShutdown);
                    _mainConnection = null;
                }
            }
            catch (Exception ex)
            {
                ServerMessageReceivedAction("Failed connect to Main server");

                NetworkComms.RemoveGlobalConnectionCloseHandler(HandleConnectionShutdown);
                _mainConnection = null;
            }
        }
        public void Start()
        {
            if (!ResolveDns())
            {
                return;
            }

            ServerMessageReceivedAction("Start connection to Main server");

            try
            {
                _mainConnection = TCPConnection.GetConnection(new ConnectionInfo(_serverConfig.IP, _serverConfig.Port));
                if (_mainConnection.ConnectionInfo.ConnectionState == ConnectionState.Established)
                {
                    NetworkComms.AppendGlobalConnectionCloseHandler(HandleConnectionShutdown);

                    _mainConnection.AppendIncomingPacketHandler <ClientInfo[]>(PacketType.REQ_OnlineClientInfos, HandleOnlineClientInfos);
                    _mainConnection.AppendIncomingPacketHandler <P2PClient>(PacketType.REQ_P2PSpecifiedClient, HandleP2PSpecifiedClient);
                    _mainConnection.AppendIncomingPacketHandler <string>(PacketType.REQ_P2PFailed, HandleP2PFailed);

                    SendLocalClientInfo();
                }
                else
                {
                    ServerMessageReceivedAction("Failed connect to Main server");

                    NetworkComms.RemoveGlobalConnectionCloseHandler(HandleConnectionShutdown);
                    _mainConnection = null;
                }
            }
            catch (Exception ex)
            {
                ServerMessageReceivedAction("Failed connect to Main server");

                NetworkComms.RemoveGlobalConnectionCloseHandler(HandleConnectionShutdown);
                _mainConnection = null;
            }
        }
 public void Close()
 {
     NetworkComms.RemoveGlobalConnectionCloseHandler(closeHandler);
 }