예제 #1
0
        private void FsttHandle4UF(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
        {
            string path  = ByteEncoding(Message, MessageCount);
            string tpath = path;

            path = Config.filepath + @"\" + Dict[Address].filepath + @"\" + path;
        }
예제 #2
0
        private void DdelHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
        {
            string path  = ByteEncoding(Message, MessageCount);
            string tpath = path;

            path = Config.filepath + @"\" + Dict[Address].filepath + @"\" + path;
            if (tpath.Replace(".", String.Empty) == "")
            {
                ErrorMessage(MessageSocket, "Directory does not Exist.");
            }
            else
            {
                try {
                    if (!Directory.Exists(path))
                    {
                        ErrorMessage(MessageSocket, "Directory does not Exist.");
                    }
                    else
                    {
                        try {
                            Directory.Delete(path);
                            TextMessage(MessageSocket, ServerControl.TEXT, "Directory Deleted.");
                        }
                        catch {
                            ErrorMessage(MessageSocket, "Can't delete <directory>. Please make sure there is no file under this directory.");
                        }
                    }
                }
                catch (Exception e) {
                    CloFunc.Errorinfo("UnExpected DDEL Fail:\n" + e.ToString());
                }
            }
        }
예제 #3
0
 private void OnStop()
 {
     if (consoleMessages)
     {
         Console.WriteLine("Stopping Website with ServerControl...");
     }
     if (_runningThreads != null)
     {
         ServerControl.UnRegisterBackgroundOperationPreCall(_preCall);
         ServerControl.UnRegisterBackgroundOperationPostCall(_postCall);
     }
     ServerControl.Stop();
     if (consoleMessages)
     {
         Console.WriteLine("Website stoppped with ServerControl.");
     }
     if (pidfile != null)
     {
         if (consoleMessages)
         {
             Console.WriteLine("Deleting pidfile...");
         }
         new FileInfo(pidfile).Delete();
         if (consoleMessages)
         {
             Console.WriteLine("Pidfile deleted.");
         }
     }
     _shutdownEvent.Set();
 }
예제 #4
0
        private void CdirHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
        {
            string path  = ByteEncoding(Message, MessageCount);
            string tpath = path;

            path = Config.filepath + @"\" + Dict[Address].filepath + @"\" + path;
            if (tpath.Replace(".", String.Empty) == "")
            {
                ErrorMessage(MessageSocket, "Illegal <directory>");
            }
            else
            {
                try {
                    if (Directory.Exists(path))
                    {
                        ErrorMessage(MessageSocket, "Directory Alread Exists.");
                    }
                    else
                    {
                        Directory.CreateDirectory(path);
                        TextMessage(MessageSocket, ServerControl.TEXT, "Directory Created.");
                    }
                }
                catch (Exception e) {
                    CloFunc.Errorinfo("UnExpected CDIR Fail: " + e.ToString());
                }
            }
        }
예제 #5
0
 private void RpasHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
 {
     try {
         string       ThisMessage = ByteEncoding(Message, MessageCount);
         StreamReader logincp     = new StreamReader(Config.userpath);//login check process
         int          tempindex   = 0;
         string       stemp       = logincp.ReadLine();
         string[]     temp        = stemp.Split(' ');//split string with whitespace.
         stemp = logincp.ReadLine();
         while (stemp != null)
         {
             ++tempindex;
             temp = stemp.Split(' ');
             if (temp[0] == Dict[Address].username)
             {
                 break;
             }
             stemp = logincp.ReadLine();
         }
         logincp.Close();
         string[] Alllines = File.ReadAllLines(Config.userpath);
         Alllines[tempindex] = Dict[Address].username + ' ' + ThisMessage;
         File.WriteAllLines(Config.userpath, Alllines);
         TextMessage(MessageSocket, ServerControl.TEXT, "ResetPassword Success.");
     }
     catch {
         //
         CloFunc.Errorinfo("Unexpected RPAS Fail.");
     }
 }
예제 #6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            currentPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            //监听退出进程
            var CurrentPro = Process.GetCurrentProcess();

            CurrentPro.EnableRaisingEvents = true;
            CurrentPro.Exited += new EventHandler(Pro_Exit);

            mainWind = new MainWin();

            //启动必要的线程
            servercontrol = new ServerControl();
            viewcontrol   = new ViewControl(mainWind);

            servercontrol.StartListenThread();
            viewcontrol.StartListenServerThread();

            mainWind.FormClosed += new FormClosedEventHandler(FormExit);

            Application.Run(mainWind);
        }
예제 #7
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // TODO: Implement Functionality Here

//            TmxHelper.NewTestSuite("name", "id", null, null, null, null);
//
//
//            TmxHelper.AddTestScenario(
//                new AddScenarioCmdletBase {
//                // new AddTmxTestScenarioCommand {
//                    Name = "name 2",
//                    Id = "id 2",
//                    TestPlatformId = null,
//                    TestSuiteId = null,
//                    Description = null
//                });

            // Tmx.Server.ServerControl.Start(@"http://localhost:12340");
            ServerControl.Start("localhost", 12340);

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
예제 #8
0
        public new void Stop()
        {
            Logger.Info(@"Rank server stopping...");

            ServerControl.Stop();
            base.Stop();
        }
예제 #9
0
 private void ByteMessage(Socket MessageSocket, ServerControl Control, byte[] Message)
 {
     byte[] textbuffer = new byte[1 + Message.Length];
     textbuffer[0] = (byte)Control;
     Message.CopyTo(textbuffer, 1);
     MessageSocket.Send(textbuffer);
 }
예제 #10
0
    public IEnumerator WaitForServer(float _waitTime)
    {
        yield return(new WaitForSeconds(_waitTime));

        while (true)
        {
            if (socketFlag == true)
            {
                socketFlag = false;
                if (ServerControl.SendCreatureList())
                {
                    StartCoroutine(ServerControl.ListenForHostileCreatureList(3.0f));
                }
                else
                {
                    NetworkErrorPanelactive();
                }

                break;
            }
        }
        while (true)
        {
            if (creatureFlag == true)
            {
                creatureFlag = false;
                break;
            }
        }
    }
예제 #11
0
    //Save parameters stored in the button to the PublicLevel and load scene
    public override void InitLevel()
    {
        StartCoroutine(ServerControl.OpenStream(3.0f));
        PublicLevel.SetLevel(hostileType, manaAmount, manaRegenTime, creatureSpawnTime, stageLevel, false, null);

        WaitForServer(3.0f);
    }
예제 #12
0
        private void DlflHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
        {
            string path  = ByteEncoding(Message, MessageCount);
            string tpath = path;

            path = Config.filepath + @"\" + Dict[Address].filepath + @"\" + path;
            if (tpath.Split('\\').ToArray().Length > 1)
            {
                ErrorMessage(MessageSocket, "Do not contain directory in <file>.");
            }
            else
            {
                try {
                    if (!File.Exists(path))
                    {
                        ErrorMessage(MessageSocket, "File does not Exist.");
                    }
                    else
                    {
                        try {
                            TextMessage(MessageSocket, ServerControl.DLFL, tpath);
                            Dict[Address].ThreadState.Download = true;
                        }
                        catch {
                            ErrorMessage(MessageSocket, "Unexpected Error.");
                        }
                    }
                }
                catch (Exception e) {
                    CloFunc.Errorinfo("UnExpected DLFL Fail:\n" + e.ToString());
                }
            }
        }
예제 #13
0
        private void FdelHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
        {
            string path  = ByteEncoding(Message, MessageCount);
            string tpath = path;

            path = Config.filepath + @"\" + Dict[Address].filepath + @"\" + path;
            if (tpath.Split('\\').ToArray().Length > 1)
            {
                ErrorMessage(MessageSocket, "Do not contain directory in <file>.");
            }
            else
            {
                try {
                    if (!File.Exists(path))
                    {
                        ErrorMessage(MessageSocket, "File does not Exist.");
                    }
                    else
                    {
                        try {
                            File.Delete(path);
                            TextMessage(MessageSocket, ServerControl.TEXT, "File Deleted.");
                        }
                        catch {
                            ErrorMessage(MessageSocket, "Can't delete <File>. Please make sure it's not occupied.");
                        }
                    }
                }
                catch (Exception e) {
                    CloFunc.Errorinfo("UnExpected FDEL Fail:\n" + e.ToString());
                }
            }
        }
예제 #14
0
        public new void Stop()
        {
            Logger.Info(@"Scene server stopping...");

            PathManager.Stop();
            ServerControl.Stop();
            base.Stop();
        }
예제 #15
0
        public MainWindow(ClientControl clientControl, ServerControl serverControl)
        {
            InitializeComponent();
            DataContext = _viewModel;

            ClientContentControl.Content = clientControl;
            ServerContentControl.Content = serverControl;
        }
예제 #16
0
        public MainWindow()
        {
            IServerControl serverControl = new ServerControl();

            InitializeComponent();
            //ContentControl.DataContext = serverControl;
            ContentControl.Content = serverControl;
        }
예제 #17
0
 private void TextMessage(Socket MessageSocket, ServerControl Control, string Message)
 {
     //these code is based on "ErrorMessage" function
     byte[] text       = System.Text.Encoding.Default.GetBytes(Message);
     byte[] textbuffer = new byte[1 + text.Length];
     textbuffer[0] = (byte)Control;
     text.CopyTo(textbuffer, 1);
     MessageSocket.Send(textbuffer);
 }
예제 #18
0
        private void FsttHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
        {
            string path  = ByteEncoding(Message, MessageCount);
            string tpath = path;

            path = Config.filepath + @"\" + Dict[Address].filepath + @"\" + path;
            if (tpath.Split('\\').ToArray().Length > 1)
            {
                ErrorMessage(MessageSocket, "Do not contain directory in <file>.");
            }
            else
            {
                try {
                    if (!File.Exists(path))
                    {
                        ErrorMessage(MessageSocket, "File does not Exist.");
                    }
                    else
                    {
                        try {
                            FileStream fp          = new FileStream(path, FileMode.Open, FileAccess.Read);//, FileShare.Read);
                            byte[]     messagebuff = new byte[2047];
                            TextMessage(MessageSocket, ServerControl.FSTT, fp.Length.ToString());
                            long   count        = (fp.Length + 2046) / 2047;
                            byte[] finalmessage = new byte[(int)(fp.Length % 2047)];
                            for (long i = 0; i < count; ++i)
                            {
                                if (i + 1 != count)
                                {
                                    fp.Read(messagebuff, 0, 2047);
                                    ByteMessage(MessageSocket, ServerControl.FILE, messagebuff);
                                }
                                else
                                {
                                    fp.Read(finalmessage, 0, finalmessage.Length);
                                    ByteMessage(MessageSocket, ServerControl.FEND, finalmessage);
                                }
                            }
                            /////////ByteMessage & TextMessage may be cat by Socket or FTP///////
                            /////////cause an unrepairable bug
                            /////////so add an [meaningless] operation here to avoid bug
                            log(Address + " < " + path + " Download Over.");
                            ////////////////////////////////////////
                            //TextMessage(MessageSocket, ServerControl.FEND, "DL END");
                            Dict[Address].ThreadState.Download = false;
                            fp.Close();
                        }
                        catch {
                            ErrorMessage(MessageSocket, "Unexpected Error.");
                        }
                    }
                }
                catch (Exception e) {
                    CloFunc.Errorinfo("UnExpected FSTT Fail:\n" + e.ToString());
                }
            }
        }
예제 #19
0
        public void Start()
        {
            Logger.Info(@"Scene server starting...");

            PathManager.Start();
            SceneManager.Instance.Init();
            //TestFight.Test();
            ServerControl.Start(mPort, mAuth, Logger);
        }
예제 #20
0
 private void FileHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
 {
     try {
         Dict[Address].fp.Write(Message, 1, MessageCount);
     }
     catch {
         CloFunc.Errorinfo("Unexpected FILE Fail.");
     }
 }
예제 #21
0
 private void FendHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
 {
     try {
         Dict[Address].fp.Write(Message, 1, MessageCount);
         log(Address + " > " + Dict[Address].fp.Name + " Upload Over.");
         Dict[Address].fp.Close();
         Dict[Address].ThreadState.Upload = false;
     }
     catch {
         CloFunc.Errorinfo("Unexpected FILE Fail.");
     }
 }
예제 #22
0
        public void WritesServerControl(bool canBlockReload, double?canSkipUntil, double?holdBack, double?partHoldBack, string expected)
        {
            var serverControl = new ServerControl
            {
                CanBlockReload = canBlockReload,
                CanSkipUntil   = canSkipUntil,
                HoldBack       = holdBack,
                PartHoldBack   = partHoldBack
            };

            AssertStreamContentEqual(expected, serverControl);
        }
예제 #23
0
        public static void Main(string[] args)
        {
            try {
                ServerControl.Port = 12340;
                ServerControl.Start(@"http://*****:*****@"Press any key to stop server . . . ");
            Console.ReadKey(true);
            ServerControl.Stop();

            /*
             * try
             * {
             *  ServerControl.Start(TestSettings.BaseUrl);
             *
             *  if (!Environment.UserInteractive)
             *  {
             *      var services = new ServiceBase[] { new ServiceControl() };
             *      ServiceBase.Run(services);
             *  }
             *  else
             *  {
             *      var service = new ServiceControl();
             *      Thread.Sleep(Timeout.Infinite);
             *  }
             * }
             * catch (Exception ex)
             * {
             *  Console.WriteLine(ex.Message);
             *  Console.WriteLine(ex.StackTrace);
             *  // Console.WriteLine(ex.InnerException.Message);
             * }
             * Console.Write("Press any key to stop server . . . ");
             * Console.ReadKey(true);
             * ServerControl.Stop();
             */
        }
예제 #24
0
 public new void Status(ConcurrentDictionary <string, string> dict)
 {
     try
     {
         if (ServerControl != null)
         {
             ServerControl.Status(dict);
         }
     }
     catch
     {
         // ...
     }
 }
예제 #25
0
 private bool AuthorityCheck(ServerControl Control, UserGroup usergroup)
 {
     if (usergroup == UserGroup.Root)
     {
         return(true);
     }
     else if (usergroup == UserGroup.Stranger)
     {
         ServerControl[] A =
         {
             ServerControl.USER,
             ServerControl.PASS,
             ServerControl.BYTE,
             ServerControl.BEND
         };
         return(-1 != Array.IndexOf(A, Control));//if "control" is not in "A" , then "indexof" will return -1.
     }
     else if (usergroup == UserGroup.Guest)
     {
         ServerControl[] A =
         {
             ServerControl.USER,
             ServerControl.PASS,
             ServerControl.DBUG,
             ServerControl.CDCD,
             ServerControl.LIST
         };
         return(-1 != Array.IndexOf(A, Control));
     }
     else if (usergroup == UserGroup.General)
     {
         ServerControl[] A =
         {
             ServerControl.USER,
             ServerControl.PASS,
             ServerControl.DBUG,
             ServerControl.DLFL,
             ServerControl.ULFL,
             ServerControl.FSTT,
             ServerControl.FILE,
             ServerControl.FEND,
             ServerControl.CDCD,
             ServerControl.LIST,
             ServerControl.RPAS
         };
         return(-1 != Array.IndexOf(A, Control));
     }
     return(false);
 }
예제 #26
0
        private void ListHandle(Socket MessageSocket, ServerControl Control, byte[] Message, IPAddress Address)
        {
            DirectoryInfo info = new DirectoryInfo(Config.filepath + @"\" + Dict[Address].filepath);

            DirectoryInfo[] infolist    = info.GetDirectories();
            FileInfo[]      Finfolist   = info.GetFiles();
            string          infoMessage = "";

            //add dir info
            for (int i = 0; i < infolist.Length; ++i)
            {
                infoMessage += infolist[i].Name;
                if (i + 1 != infolist.Length)
                {
                    infoMessage += "\t";
                }
            }
            //add file info
            for (int i = 0; i < Finfolist.Length; ++i)
            {
                if (i == 0 && infolist.Length == 0)
                {
                    infoMessage += Finfolist[i].Name;
                }
                else
                {
                    infoMessage += "\t" + Finfolist[i].Name;
                }
            }
            byte[] listMessage = Encoding.Default.GetBytes(infoMessage);
            int    count       = (listMessage.Length + (2048 - 2)) / (2048 - 1);//ceil

            byte[] smessage;
            for (int i = 0; i < count; ++i)
            {
                if (i + 1 != count)
                {
                    smessage    = listMessage.Take(2047).ToArray();
                    listMessage = listMessage.Skip(2047).ToArray();
                }
                else
                {
                    smessage = listMessage;
                }
                ByteMessage(MessageSocket, ServerControl.LIST, smessage);
            }
            ///may crash.
            TextMessage(MessageSocket, ServerControl.LEND, "OVER.");
        }
예제 #27
0
        protected override void OnStartup(StartupEventArgs e)
        {
            var ipAddress = ConfigurationManager.AppSettings["ipaddress"];
            var port      = int.Parse(ConfigurationManager.AppSettings["port"]);

            var clientControl = new ClientControl(new TheClient(ipAddress, port), new ClientControlViewModel {
                IpAddress = ipAddress, Port = port
            });
            var serverControl = new ServerControl(new Server(ipAddress, port), new ServerControlViewModel {
                IpAddress = ipAddress, Port = port
            });
            var mainWindow = new MainWindow(clientControl, serverControl);

            MainWindow.ShowDialog();
        }
예제 #28
0
        public static void CreateServerList()
        {
            var _Margin = new System.Windows.Thickness(15, 5, 15, 0);

            foreach (Server s in References.serverCollection.Servers)
            {
                ServerControl serverControl = Application.Current.Dispatcher.Invoke(() => new ServerControl());
                serverControl.Dispatcher.Invoke(() => serverControl.Flag.Source = GetFlag(s));
                serverControl.Dispatcher.Invoke(() => { serverControl.Margin = _Margin; });
                serverControl.Dispatcher.Invoke(() => { serverControl.Server = s; });
                serverControl.Dispatcher.Invoke(() => { serverControl.ServerNameLabel.Content = s.Name; });
                serverControl.Dispatcher.Invoke(() => { serverControl.Visibility = Visibility.Hidden; });
                MainWindow.Instance.ServerStackPanel.Dispatcher.Invoke(() => MainWindow.Instance.ServerStackPanel.Children.Add(serverControl));
            }
            RefreshInteface();
        }
예제 #29
0
 private void ByteHandle(Socket MessageSocket, ServerControl Control, byte[] Message, int MessageCount, IPAddress Address)
 {
     try {
         if (Dict[Address].ThreadState.transmission)
         {
             Dict[Address].ByteBuff = CloFunc.Bytecat(Dict[Address].ByteBuff, Message.Skip(1).ToArray());
         }
         else
         {
             Dict[Address].ThreadState.transmission = true;
             Dict[Address].ByteBuff = Message.Skip(1).ToArray();
         }
     }
     catch {
         //CloFunc.Errorinfo("Unexpected Byte Fail.");
     }
 }
예제 #30
0
        private void ServerControl_Close(object sender, EventArgs e)
        {
            ServerControl            serverControl = (ServerControl)sender;
            ServerControlDataContext dataContext   = (ServerControlDataContext)serverControl.DataContext;

            for (int i = 0; i < ServerForms.Items.Count; i++)
            {
                TabItem currentTab = (TabItem)ServerForms.Items[i];

                ServerControl currentServerControl = currentTab.Content as ServerControl;
                if (currentServerControl == null || currentServerControl.DataContext != dataContext)
                {
                    continue;
                }

                ServerForms.Items.RemoveAt(i);
                break;
            }
        }
 void Start()
 {
     //		if (!BrainCloudWrapper.GetBC ().IsAuthenticated())
     {
     //			Application.LoadLevel("Login");
     }
     //		else
     {
         UpdateScoreText();
     //			ReadStatistics();
     }
     serverControl = new ServerControl ();
 }
예제 #32
0
 /// <summary>
 /// 
 /// </summary>
 void Awake()
 {
     Instance = this;
 }
    // Use this for initialization
    void Start()
    {
        m_username = PlayerPrefs.GetString("username");
        serverControl = new ServerControl ();

        // Stores the password in plain text directly in the unity store.
        // This is obviously not secure but speeds up debugging/testing.
        //		m_password = PlayerPrefs.GetString("password");
    }