Ejemplo n.º 1
0
 void initializeALLservants()
 {
     menu = new Menu();
     servants.Add(menu);
     setting = new Setting();
     servants.Add(setting);
     selectDeck = new selectDeck();
     servants.Add(selectDeck);
     room = new Room();
     servants.Add(room);
     cardDescription = new CardDescription();
     deckManager     = new DeckManager();
     servants.Add(deckManager);
     ocgcore = new Ocgcore();
     servants.Add(ocgcore);
     selectServer = new SelectServer();
     servants.Add(selectServer);
     roomList = new RoomList();
     servants.Add(roomList);
     book = new Book();
     servants.Add(book);
     selectReplay = new selectReplay();
     servants.Add(selectReplay);
     puzzleMode = new puzzleMode();
     servants.Add(puzzleMode);
     aiRoom = new AIRoom();
     servants.Add(aiRoom);
 }
Ejemplo n.º 2
0
        public NpcServerSingleThreaded(INpcServerCallback callback, NpcExecutor npcExecutor, INpcHtmlGenerator htmlGenerator, UInt16 port)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (npcExecutor == null)
            {
                throw new ArgumentNullException("npcExecutor");
            }
            if (htmlGenerator == null)
            {
                throw new ArgumentNullException("htmlGenerator");
            }

            this.callback      = callback;
            this.npcExecutor   = npcExecutor;
            this.htmlGenerator = htmlGenerator;

            Socket listenSocket = new Socket(IPAddress.Any.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            listenSocket.Bind(new IPEndPoint(IPAddress.Any, port));
            listenSocket.Listen(Backlog);
            callback.ServerListening(listenSocket);

            selectServer = new SelectServer(false, new Buf(SingleThreadedReceiveBufferLength));
            selectServer.control.AddListenSocket(listenSocket, AcceptCallback);
        }
Ejemplo n.º 3
0
        public static void SelectServerFailed(LoginClient client, SelectServer error)
        {
            using var packet = new Packet(PacketType.SELECT_SERVER);
            packet.Write <sbyte>((sbyte)error);
            packet.Write(new byte[4]);

            client.SendPacket(packet);
        }
Ejemplo n.º 4
0
        public NpcServerSingleThreaded(INpcServerCallback callback, NpcExecutor npcExecutor, INpcHtmlGenerator htmlGenerator, Socket listenSocket)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (npcExecutor == null)
            {
                throw new ArgumentNullException("npcExecutor");
            }
            if (htmlGenerator == null)
            {
                throw new ArgumentNullException("htmlGenerator");
            }

            this.callback      = callback;
            this.npcExecutor   = npcExecutor;
            this.htmlGenerator = htmlGenerator;

            selectServer = new SelectServer(false, new Buf(SingleThreadedReceiveBufferLength));
            selectServer.control.AddListenSocket(listenSocket, AcceptCallback);
        }
Ejemplo n.º 5
0
 void SendServerSelect(String Ip, int Port)
 {
     SocketUDP.SendTo(SelectServer.Client_Submit().ToByte(), new IPEndPoint(IPAddress.Parse(Ip), Port));
 }
 public static void AddServer_Click(object sender, EventArgs e)
 {
     SelectServer.OpenScreen(true);
 }
 /* ServerList Load Checks */
 public static void SelectServerBtn_Click(object sender, EventArgs e)
 {
     SelectServer.OpenScreen(false);
 }
        static void Main(String[] args)
        {
            //NfsServerLog.stopwatchTicksBase = Stopwatch.GetTimestamp();

            RemoteDataServerProgramOptions options = new RemoteDataServerProgramOptions();
            List <String> nonOptionArguments       = options.Parse(args);

            if (nonOptionArguments.Count < 2)
            {
                options.ErrorAndUsage("Expected at least 2 non-option arguments but got '{0}'", nonOptionArguments.Count);
                return;
            }
            if (nonOptionArguments.Count % 2 == 1)
            {
                options.ErrorAndUsage("Expected an even number of non-option arguments but got {0}", nonOptionArguments.Count);
            }

            UniqueIndexObjectDictionary <ShareObject> shareObjects = new UniqueIndexObjectDictionary <ShareObject>(
                512, 512, 4096, 1024);

            RootShareDirectory[] rootShareDirectories = new RootShareDirectory[nonOptionArguments.Count / 2];
            for (int i = 0; i < rootShareDirectories.Length; i++)
            {
                String localPathAndName = nonOptionArguments[2 * i];
                String remoteShareName  = nonOptionArguments[2 * i + 1];

                DirectoryShareObject directoryShareObject = new DirectoryShareObject(localPathAndName, remoteShareName, null);
                UInt32 id = shareObjects.Add(directoryShareObject);
                directoryShareObject.id = id;

                rootShareDirectories[i] = new RootShareDirectory(directoryShareObject);
            }

            //
            // Options not exposed via command line yet
            //
            Int32 mountListenPort = 59733;
            Int32 backlog         = 4;

            UInt32 readSizeMax = 65536;
            UInt32 suggestedReadSizeMultiple = 4096;

            //
            // Listen IP Address
            //
            IPAddress listenIPAddress = options.listenIPAddress.ArgValue;

            //
            // Npc Server
            //
            IPEndPoint npcServerEndPoint = !options.npcListenPort.set ? null :
                                           new IPEndPoint(listenIPAddress, options.npcListenPort.ArgValue);

            //
            // Logging Options
            //

            /*
             * TextWriter selectServerEventsLog = null;
             * if (options.logLevel.ArgValue != LogLevel.None)
             * {
             *  TextWriter logWriter;
             *  if (options.logFile.set)
             *  {
             *      logWriter = new StreamWriter(new FileStream(options.logFile.ArgValue, FileMode.Create, FileAccess.Write, FileShare.Read));
             *  }
             *  else
             *  {
             *      logWriter = Console.Out;
             *  }
             *
             *  NfsServerLog.sharedFileSystemLogger = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;
             *  NfsServerLog.rpcCallLogger = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;
             *  NfsServerLog.warningLogger = (options.logLevel.ArgValue >= LogLevel.Warning) ? logWriter : null;
             *  NfsServerLog.npcEventsLogger = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;
             *
             *  RpcPerformanceLog.rpcMessageSerializationLogger = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;
             *
             *  selectServerEventsLog = (options.logLevel.ArgValue >= LogLevel.All) ? logWriter : null;
             * }
             */

            //
            // Permissions
            //
            //ModeFlags defaultDirectoryPermissions =
            //    ModeFlags.OtherExecute | ModeFlags.OtherWrite | ModeFlags.OtherRead |
            //    ModeFlags.GroupExecute | ModeFlags.GroupWrite | ModeFlags.GroupRead |
            //    ModeFlags.OwnerExecute | ModeFlags.OwnerWrite | ModeFlags.OwnerRead;
            /*ModeFlags.SaveSwappedText | ModeFlags.SetUidOnExec | ModeFlags.SetGidOnExec;*/
            //ModeFlags defaultFilePermissions =
            //    ModeFlags.OtherExecute | ModeFlags.OtherWrite | ModeFlags.OtherRead |
            //    ModeFlags.GroupExecute | ModeFlags.GroupWrite | ModeFlags.GroupRead |
            //    ModeFlags.OwnerExecute | ModeFlags.OwnerWrite | ModeFlags.OwnerRead;
            /*ModeFlags.SaveSwappedText | ModeFlags.SetUidOnExec | ModeFlags.SetGidOnExec;*/
            //IPermissions permissions = new ConstantPermissions(defaultDirectoryPermissions, defaultFilePermissions);



            SharedFileSystem sharedFileSystem = new SharedFileSystem(shareObjects, /*permissions, */ rootShareDirectories);

            Buf sendBuffer = new Buf(4096, 1024);

            RemoteDataServer remoteDataServer = new RemoteDataServer(sharedFileSystem, sendBuffer);

            //
            // Create Endpoints
            //

            SelectServer selectServer = new SelectServer(false, new Buf(4096, 4096));

            //this.serverStartTimeStopwatchTicks = Stopwatch.GetTimestamp();

            {
                if (listenIPAddress == null)
                {
                    listenIPAddress = IPAddress.Any;
                }
                IPEndPoint remoteDataEndPoint = new IPEndPoint(listenIPAddress, RemoteData.DefaultPort);
                {
                    Socket tcpSocket = new Socket(remoteDataEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    tcpSocket.Bind(remoteDataEndPoint);
                    tcpSocket.Listen(backlog);
                    selectServer.control.AddReceiveSocket(tcpSocket, remoteDataServer.AcceptCallback);
                }
                {
                    Socket udpSocket = new Socket(remoteDataEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                    udpSocket.Bind(remoteDataEndPoint);
                    selectServer.control.AddReceiveSocket(udpSocket, remoteDataServer.DatagramHandler);
                }
            }



            /*
             * if (npcServerEndPoint != null)
             * {
             #if !WindowsCE
             *  Nfs3Server.NfsServerManager nfsServerManager = new Nfs3Server.NfsServerManager(nfsServer);
             *  NpcReflector reflector = new NpcReflector(
             *      new NpcExecutionObject(nfsServerManager, "Nfs3ServerManager", null, null),
             *      new NpcExecutionObject(nfsServer, "Nfs3Server", null, null),
             *      new NpcExecutionObject(portMapServer, "Portmap2Server", null, null),
             *      new NpcExecutionObject(mountServer, "Mount1And3Server", null, null)
             *      );
             *  tcpListeners.Add(new TcpSelectListener(npcServerEndPoint, 32, new NpcStreamSelectServerCallback(
             *      NpcCallback.Instance, reflector, new DefaultNpcHtmlGenerator("NfsServer", reflector))));
             #endif
             * }
             */

            selectServer.Run();
        }
Ejemplo n.º 9
0
        private void Server_GetNewMessage(byte[] Content, MessageBase Message, System.Net.EndPoint FromIP)
        {
            if (BlackMembers.Where(ip => FromIP == ip).Count() > 0)
            {
                return;                                                    //如果是黑名单就拒收
            }
            String TagMessage = "";

            if (Message.MessageType == SocketMessageType.IsOnLine)
            {
                IsOnLine onlin = IsOnLine.ToModel <IsOnLine>(Content);
                if (OnLineUsers.Keys.Where(k => k.Equals(FromIP)).Count() > 0)
                {
                    OnLineUsers[FromIP] = DateTime.Now;
                }
                else
                {
                    OnLineUsers.Add(FromIP, DateTime.Now);
                    Dispatcher.Invoke(() =>
                    {
                        LIST_OnlineUsers.Items.Add(new
                        {
                            IpAddress = FromIP,
                            Content   = onlin,
                        });
                    });
                }
                TagMessage = "在线确认消息";
            }
            else if (Message.MessageType == SocketMessageType.SelectServer)
            {
                Server.SendTo(SelectServer.Server_Return(StaticResource.IPV4Address + ":" + StaticResource.ServerPort).ToByte(), FromIP);
            }
            else if (Message.MessageType == SocketMessageType.BulletChat)
            {
                BulletChatModel bullet = BulletChatModel.ToModel <BulletChatModel>(Content);
                TagMessage = $"{bullet.SendUser}发送的弹幕:{bullet.Message}";
                foreach (EndPoint user in OnLineUsers.Keys)
                {
                    if (BlackMembers.Where(ip => ip.Equals(user)).Count() > 0)
                    {
                        continue;
                    }
                    Server.SendTo(Content, user);
                }
            }
            Dispatcher.Invoke(() =>
            {
                if (LIST_Messages.Items.Count >= 10)
                {
                    LIST_Messages.Items.Clear();
                }
                LIST_Messages.Items.Add(new
                {
                    Tag         = TagMessage,
                    IpAddress   = FromIP,
                    MessageType = Message.MessageType,
                    Length      = Content.Length,
                });
            });
        }