예제 #1
0
        public winMain()
        {
            InitializeComponent();

            server = new SyncIOServer(SyncIO.Transport.TransportProtocal.IPv4, RemoteConfig.GetPackager());

            server.SetHandler <HandshakePacket>((client, packet) => {
                var nsClientInfo = new NSClient(packet.Username, packet.AppID);
                client.Tag       = nsClientInfo;
                client.Send(new HandshakeResponsePacket(true));
            });

            server.SetDefaultRemoteFunctionAuthCallback((client, func) => {
                var FuncInfo = func.Tag as FunctionInfo;
                if (FuncInfo == null)
                {
                    return(false);
                }

                var nsClientInfo = client.Tag as NSClient;
                if (nsClientInfo == null)
                {
                    return(false);
                }

                var succ = nsClientInfo.AppID.Equals(FuncInfo.ID) &&
                           NetSealAPI.IsValidConnection(FuncInfo.ApiCode, client, nsClientInfo.Username);

                if (!succ)
                {
                    client.Disconnect(new AccessViolationException());
                }

                return(succ);
            });

            LoadFunctions();

            foreach (var port in ConfigLoader.GetPorts())
            {
                server.ListenTCP(port);
            }

            var listeningPorts = server.Count();

            if (listeningPorts < 1)
            {
                lblStatus.Content = $"Idle. (listening on {listeningPorts} ports).";
            }
            else
            {
                lblStatus.Content = $"listening on {listeningPorts} ports.";
            }
        }