Ejemplo n.º 1
0
    // public static FightClientForUnity3D Instance
    // {
    //     get { return instance; }
    // }
    // Use this for initialization
    void Awake()
    {
        client = new FSClient();

        client.unityClient = this;
        client.Connect("127.0.0.1", 12345, 10);

        // foreach (JoyStick joyStick in joySticks)
        // {
        //     InputCenter.Instance.AddJoyStick(joyStick.frameKey,joyStick.GetInfo());
        // }

        //V2 v2 = new V2(1, 0);
        //for (int i =0; i <= 360; i+=30)
        //{
        //   // Debug.Log("sin"+i+":"+MathR.SinAngle(new Ratio(i)).ToFloat());
        //   // Debug.Log("cos" + i + ":" + MathR.CosAngle(new Ratio(i)).ToFloat());
        //}

        // InputCenter.Instance.framUpdate += FrameUpdate;
        //  V2 v2 = new V2(-1,-1);
        //  Debug.Log(v2.ToRotation());
        //  Debug.LogError((10 & 2) == 2);
        // Debug.LogError(V2.left+V2.up);
        //Ratio r = new Ratio(16);
        //Debug.Log(r.SQR(r));
        //Debug.Log(r.InvSqrt(16));

        // V2 v2 = new V2(-5, 99);
        // Debug.Log("(-5, 99)" + v2.x * v2.x + "," + v2.y * v2.y);
        //  Debug.Log("normalized"+v2.normalized);
    }
Ejemplo n.º 2
0
 public override void Init(FSClient client)
 {
     base.Init(client);
     rigibody.useCheckCallBack = true;
     isTrigger = true;
     startTime = client.inputCenter.Time;
 }
Ejemplo n.º 3
0
 public override void Init(FSClient client, int clientId = -1)
 {
     base.Init(client, clientId);
     tag = "Bullet";
     rigibody.useCheckCallBack = true;
     isTrigger = true;
     startTime = client.inputCenter.Time;
 }
Ejemplo n.º 4
0
    public void Init(FSClient client)
    {
        this.client           = client;
        map                   = new GridMap();
        map.CreatTileCallBack = CreateShap;
        map.Init(30, 30, mapScale, client.random.Range);
        map.RandomRoom();

        map.PrimConnect();
        mapView.ShowMap(map);
    }
    void Awake()
    {
        joySticks = new List <JoyStick>();
        joySticks.AddRange(GetComponentsInChildren <JoyStick>());
        netButtons = new List <NetButton>();
        netButtons.AddRange(GetComponentsInChildren <NetButton>());
        client = new FSClient();

        client.unityClient = this;
        //   client.Connect("127.0.0.1", 12345,10);
        client.Connect(GameUser.user.fightRoom.ip, int.Parse(GameUser.user.fightRoom.port), 10, GetComponentsInChildren <IGameManager>());
    }
Ejemplo n.º 6
0
        public static void Init()
        {
            FootStone.NLogger.Init(logger);

            if (!(client is null))
            {
                return;
            }
            client = new FSClient();
            client.IceOptions(iceOptions =>
            {
                iceOptions.EnableDispatcher = false;
                //iceOptions.PushObjects.Add(new PlayerPushI());
                //iceOptions.PushObjects.Add(new ZonePushI());
            });
            client.Start();
        }
Ejemplo n.º 7
0
        static void CommonTest()
        {
            var client = new FSClient(512 * 1024, 1, Properties.Settings.Default.StorageUrl, 1);

            SimpleActionResult response;

            Console.WriteLine("Sending file to a server...");
            using (var file = new FileStream(Path.Combine("files", BinaryFileName), FileMode.Open))
            {
                response = client.SendFile(file, BinaryFileName, "1", "test");
            }
            Console.WriteLine(response.Status);

            Console.WriteLine("Checking file existance on a server...");
            response = client.FileExists(BinaryFileName, "1", "test");
            Console.WriteLine(response.Status);

            Console.WriteLine("Checking file MD5 sum on a server...");
            response = client.FileMD5(BinaryFileName, "1", "test");
            using (var file = new FileStream(Path.Combine("files", BinaryFileName), FileMode.Open))
            {
                Console.WriteLine(((StringActionResult)response).Value == FSClient.FileMD5Local(file));
            }

            Console.WriteLine("Checking file length on a server...");
            response = client.FileLength(BinaryFileName, "1", "test");
            using (var file = new FileStream(Path.Combine("files", BinaryFileName), FileMode.Open))
            {
                Console.WriteLine(((LongActionResult)response).Value == file.Length);
            }

            Console.WriteLine("Checking get file from a server...");
            using (var file = new FileStream(Path.Combine("files", TextFileName), FileMode.Open))
            {
                client.SendFile(file, TextFileName, "1", "test");
            }
            response = client.GetFile(TextFileName, "1", "test");
            using (var sr = new StreamReader(((StreamActionResult)response).Value))
            {
                Console.WriteLine(string.Format("File data is: {0}", sr.ReadToEnd()));
            }

            Console.WriteLine("Deleting file from a server...");
            response = client.DelFile(BinaryFileName, "1", "test");
            Console.WriteLine(response.Status);
        }
Ejemplo n.º 8
0
        public async Task Test(string ip, int port, int count, ushort startIndex, bool needNetty)
        {
            NLogger.Info($"begin test,count:${count},startIndex:{startIndex},needNetty:{needNetty}");

            var client = new FSClient();

            client.IceOptions(iceOptions =>
            {
                iceOptions.EnableDispatcher = false;
                //iceOptions.PushObjects.Add(new PlayerPushI());
                //iceOptions.PushObjects.Add(new ZonePushI());
            });

            //启动主线程
            //Thread thread = new Thread(new ThreadStart(async () =>
            //{
            //    do
            //    {
            //        client.Update();
            //        await Task.Delay(33);
            //     //   Thread.Sleep(33);
            //    } while (true);
            //}));
            //thread.Start();

            client.Start();

            for (ushort i = startIndex; i < startIndex + count; ++i)
            {
                var sessionId = "session" + i;
                try
                {
                    var session = await client.CreateSession(ip, port);

                    _ = RunSession(session, i, 20, needNetty);
                }catch (System.Exception e)
                {
                    NLogger.Error(e.ToString());
                }
                playerCount++;
                await Task.Delay(10);
            }
            NLogger.Info("all session created:" + count);
        }
    // public static FightClientForUnity3D Instance
    // {
    //     get { return instance; }
    // }
    // Use this for initialization
    void Awake()
    {
        joySticks = new List <JoyStick>();
        joySticks.AddRange(GetComponentsInChildren <JoyStick>());
        netButtons = new List <NetButton>();
        netButtons.AddRange(GetComponentsInChildren <NetButton>());
        client = new FSClient();

        client.unityClient = this;
        //   client.Connect("127.0.0.1", 12345,10);
        client.Connect(GameUser.user.fightRoom.ip, int.Parse(GameUser.user.fightRoom.port), 10, GetComponentsInChildren <IGameManager>());
        //  client.Connect("172.16.252.231", 12345,10);
        // foreach (JoyStick joyStick in joySticks)
        // {
        //     InputCenter.Instance.AddJoyStick(joyStick.frameKey,joyStick.GetInfo());
        // }

        //V2 v2 = new V2(1, 0);
        //for (int i =0; i <= 360; i+=30)
        //{
        //   // Debug.Log("sin"+i+":"+MathR.SinAngle(new Ratio(i)).ToFloat());
        //   // Debug.Log("cos" + i + ":" + MathR.CosAngle(new Ratio(i)).ToFloat());
        //}

        // InputCenter.Instance.framUpdate += FrameUpdate;
        //  V2 v2 = new V2(-1,-1);
        //  Debug.Log(v2.ToRotation());
        //  Debug.LogError((10 & 2) == 2);
        // Debug.LogError(V2.left+V2.up);
        //Ratio r = new Ratio(16);
        //Debug.Log(r.SQR(r));
        //Debug.Log(r.InvSqrt(16));

        // V2 v2 = new V2(-5, 99);
        // Debug.Log("(-5, 99)" + v2.x * v2.x + "," + v2.y * v2.y);
        //  Debug.Log("normalized"+v2.normalized);

        // for (FixedNumber i = FixedNumber.Zero; i < new FixedNumber(360); i+=new FixedNumber(0.1f))
        // {
        //     Debug.LogError(i+"du to direction= "+(new Vector3(0,360,0)- i.ToUnityRotation().eulerAngles));
        // }
        //Fixed.RotationLerp(Fixed.Zero,new Fixed(150),new Fixed(1));
    }
Ejemplo n.º 10
0
        static void ParallelLoadTest(int threadsNum)
        {
            Random rnd           = new Random();
            bool   success       = true;
            var    mutex         = new object();
            var    time          = DateTime.Now;
            string localChecksum = FSClient.FileMD5Local(new FileStream(Path.Combine("files", BinaryFileName), FileMode.Open, FileAccess.Read, FileShare.Read));
            var    result        = Parallel.For(0, threadsNum, (i, state) =>
            {
                var client = new FSClient(512 * 1024, 10,
                                          Properties.Settings.Default.
                                          StorageUrl, threadsNum);
                string id = rnd.Next().ToString();
                using (
                    var file =
                        new FileStream(Path.Combine("files", BinaryFileName),
                                       FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var response = client.SendFile(file, BinaryFileName, id,
                                                   "test");
                    var remoteChecksum = client.FileMD5(BinaryFileName, id, "test").Value;
                    if (response.Status != ActionStatus.Ok || localChecksum != remoteChecksum)
                    {
                        lock (mutex)
                        {
                            success = false;
                        }
                    }

                    client.DelFile(BinaryFileName, id, "test");
                }
            });

            while (!result.IsCompleted)
            {
                Thread.Sleep(100);
            }
            Console.WriteLine(string.Format("Success: {0}; time: {1}", success, (DateTime.Now - time).TotalSeconds));
        }
Ejemplo n.º 11
0
    public void Init(FSClient client)
    {
        var map       = client.GetManager <RandomMapCreator>();
        var playerPos = Fixed2.zero;

        if (map)
        {
            playerPos = map.GetRandomPos();
        }
        else
        {
            playerPos = new Fixed2(client.random.Range(0, 20), client.random.Range(0, 20));
        }

        int count = GameUser.user.fightRoom.playerInfos.Count;

        for (int i = 0; i < count; i++)
        {
            var player = new PlayerData();
            player.Init(client, i);

            if (map != null)
            {
                player.transform.Position = playerPos + Fixed2.left * i.ToFixed();
            }
            else
            {
                player.transform.Position = new IDG.Fixed2(0, i);
            }

            client.objectManager.Instantiate(player);
        }

        for (int i = 0; i < m_nItemCount; i++)
        {
            ItemData item;
            if (i % 2 == 0)
            {
                var Titem = new SkillItem();
                item = Titem;
                Titem.Init(client);
                if (client.random.Range(0, 100) < 50)
                {
                    Titem.skillId = SkillId.拳击右直;
                }
                else
                {
                    Titem.skillId = SkillId.拳击左直;
                }
            }
            else
            {
                var Titem = new WeaponItem();
                item = Titem;
                Titem.Init(client);
                Titem.weaponId = WeaponId.F57;
            }

            if (map)
            {
                item.transform.Position = map.GetRandomPos();
            }
            else
            {
                item.transform.Position = new Fixed2(client.random.Range(0, 20), client.random.Range(0, 20));
            }
            client.objectManager.Instantiate(item);
        }

        for (int i = 0; i < enemy; i++)
        {
            var item = new ZombieData();
            item.Init(client);
            if (map)
            {
                item.transform.Position = map.GetRandomPos();
            }
            else
            {
                item.transform.Position = new Fixed2(client.random.Range(0, 20), client.random.Range(0, 20));
            }
            client.objectManager.Instantiate(item);
        }
    }
Ejemplo n.º 12
0
 public override void Init(FSClient client, int clientId = -1)
 {
     base.Init(client, clientId);
     rigibody.useCheckCallBack = true;
     isTrigger = true;
 }
Ejemplo n.º 13
0
 public void Init(FSClient client)
 {
     teamCount = 12;
     enemyTeam = new bool[teamCount, teamCount];
     SetEnemy(1, 2);
 }
Ejemplo n.º 14
0
        private void VKUpload()
        {
            if (_view.Check())
            {
                _view.UpdateSettings(_settings);
                _settings.Save();

                // хэштэги
                string hashtags = _settings.Hashtags;

                // одна картинка - один пост
                // какой шаг между постами (часов)
                int postTimeGap;
                if (_settings.ThroughoutTheDay)
                {
                    int minHour = _settings.TimeMin;
                    int maxHour = _settings.TimeMax;

                    postTimeGap = (maxHour - minHour) / _settings.MaxPostOnDay;
                }
                else
                {
                    postTimeGap = _settings.PostStep;
                }

                double?  longitude       = _settings.Longitude;
                double?  latitude        = _settings.Latitude;
                Location initialLocation = null;
                if (_settings.PlaceGeoPosition && longitude != null && latitude != null)
                {
                    initialLocation = new Location()
                    {
                        Longitude = longitude.Value,
                        Latitude  = latitude.Value
                    };
                }
                double?squareWidth  = _settings.SquareWidth;
                double?locationStep = _settings.LocationStep;  // по умолчанию 0,0016 что примерно 550м

                // в каждом посте один анонимный опрос
                Poll poll = new Poll()
                {
                    Question = "...",
                    Answers  = new List <string>()
                    {
                        "ЗАШЛО",
                        "НЕ ЗАШЛО"
                    }
                };



                int      postCounter        = 0;
                int      dayCounter         = 0;
                int      dailyPostCounter   = 0;
                DateTime dailyFirstPostDate = _settings.StartDate;
                int      locX           = 0;
                int      locY           = 0;
                int?     maxSquarePosts = squareWidth != null ? (int?)squareWidth.Value / 550 : null;

                string completedFolder = $"{_settings.ContentPath}\\Completed";
                if (!Directory.Exists(completedFolder))
                {
                    Directory.CreateDirectory(completedFolder);
                }

                foreach (var contentInfo in FSClient.GetContentFromFolder(_settings.ContentPath))
                {
                    if (contentInfo.IsVideo() && !_settings.LoadVideo)
                    {
                        continue;
                    }

                    if (contentInfo.IsPhoto() && !_settings.LoadPictures)
                    {
                        continue;
                    }

                    if (postCounter == _settings.TotalPosts)
                    {
                        _view.ShowMessage("Операция выполнена");
                        break;
                    }

                    if (_settings.MaxPostOnDay != -1 && dailyPostCounter == _settings.MaxPostOnDay)
                    {
                        dailyPostCounter = 0;
                        dayCounter++;
                    }


                    // вычисление даты
                    DateTime postDate = dailyFirstPostDate.AddDays(dayCounter).AddHours(postTimeGap * dailyPostCounter);

                    // вычисление геолокации
                    Location newLocation = null;
                    if (initialLocation != null && locationStep != null && squareWidth != null && maxSquarePosts != null)
                    {
                        newLocation           = new Location();
                        newLocation.Latitude  = initialLocation.Latitude + locationStep.Value * locX;
                        newLocation.Longitude = initialLocation.Longitude - locationStep.Value * locY;
                    }

                    try
                    {
                        _vk.WallPost(_settings.GroupId, postDate, hashtags, contentInfo, poll, newLocation);
                    }
                    catch (Exception ex)
                    {
                        _view.ShowMessage($"Произошла ошибка - {ex.Message}");
                    }

                    if (_settings.DeleteAfterLoad)
                    {
                        File.Delete(contentInfo.FullName);
                    }
                    else
                    {
                        string dstFilename = $"{completedFolder}\\{contentInfo.Name}";
                        if (File.Exists(dstFilename))
                        {
                            dstFilename = $"{completedFolder}\\{contentInfo.NameWithoutExtension}-{Guid.NewGuid().ToString()}{contentInfo.Extension}";
                        }
                        else
                        {
                            dstFilename = $"{completedFolder}\\{contentInfo.Name}";
                        }

                        File.Move(contentInfo.FullName, dstFilename);
                    }

                    dailyPostCounter++;
                    postCounter++;
                    locX++;

                    if (maxSquarePosts != null)
                    {
                        if (locX > maxSquarePosts)
                        {
                            locX = 0;
                            locY++;
                        }
                        if (locY > maxSquarePosts)
                        {
                            locY = 0;
                        }
                    }
                }

                _view.ShowMessage("Операция выполнена");
            }
        }
Ejemplo n.º 15
0
        static void BigFileTest(long sizeMb)
        {
            var testFile = "test.dat";
            var time     = DateTime.Now;

            Console.WriteLine("Creating test file...");
            Random rnd = new Random();
            string id  = rnd.Next(int.MaxValue).ToString();

            using (var sw = new FileStream(testFile, FileMode.Create))
            {
                var buf = new byte[1048576];
                for (long i = 0; i < sizeMb; i++)
                {
                    rnd.NextBytes(buf);
                    sw.Write(buf, 0, buf.Length);
                }
            }
            Console.WriteLine(string.Format("Done in {0} seconds", (DateTime.Now - time).TotalSeconds));

            time = DateTime.Now;
            Console.WriteLine("Sending file to storage...");
            var client = new FSClient(512 * 1024, 10, Properties.Settings.Default.StorageUrl, 1);

            using (var file = new FileStream(testFile, FileMode.Open))
            {
                var sendResult = client.SendFile(file, testFile, id, "test");
                if (sendResult.Status != ActionStatus.Ok)
                {
                    Console.WriteLine("Test result: failed while sending file to storage!");
                    return;
                }
            }
            Console.WriteLine(string.Format("Done in {0} seconds", (DateTime.Now - time).TotalSeconds));

            string localChecksum;
            string remoteChecksum;

            time = DateTime.Now;
            Console.WriteLine("Calculating local MD5...");
            using (var file = new FileStream(testFile, FileMode.Open))
            {
                localChecksum = FSClient.FileMD5Local(file);
            }
            Console.WriteLine(string.Format("Done in {0} seconds", (DateTime.Now - time).TotalSeconds));

            time = DateTime.Now;
            Console.WriteLine("Calculating remote MD5...");
            var checksumResult = client.FileMD5(testFile, id, "test");

            if (checksumResult.Status != ActionStatus.Ok)
            {
                Console.WriteLine("Test result: failed while calculating file checksum!");
                return;
            }
            remoteChecksum = checksumResult.Value;
            Console.WriteLine(string.Format("Done in {0} seconds", (DateTime.Now - time).TotalSeconds));

            client.DelFile(testFile, id, "test");
            Console.WriteLine(string.Format("Test result: {0}", localChecksum == remoteChecksum));
        }
Ejemplo n.º 16
0
 void IGameManager.Init(FSClient client)
 {
     viewPool = new Stack <HpView>();
     mainCam  = (client.unityClient as FightClientForUnity3D).mainCamera;
 }
Ejemplo n.º 17
0
 // Start is called before the first frame update
 public void Init(FSClient client)
 {
     this.client = client;
 }
Ejemplo n.º 18
0
        public bool Check()
        {
            string contentFolder = textBoxContentPath.Text;

            if (String.IsNullOrEmpty(contentFolder) || !Directory.Exists(contentFolder))
            {
                MessageBox.Show("Операция не может быть выполнена - не выбран каталог загрузки");
                return(false);
            }



            long selectedGroupId = (long)comboBoxGroups.SelectedValue;

            if (selectedGroupId == -1)
            {
                MessageBox.Show("Операция не может быть выполнена - не выбрана группа");
                return(false);
            }

            // алгоритм создания отложенных постов
            var contentLst = FSClient.GetContentFromFolder(contentFolder);

            if (contentLst.Count == 0)
            {
                MessageBox.Show("Операция не может быть выполнена - отсутствуют файлы для загрузки");
                return(false);
            }

            // максимальное количество постов
            int maxPostCount = int.Parse(textBoxMaxPostCount.Text);

            if (maxPostCount == 0)
            {
                MessageBox.Show("Операция не может быть выполнена - не установлено максимально возможное количетсво постов");
                return(false);
            }

            // сколько постов на день
            int maxPostOnDay = int.Parse(textBoxPostOnDayCount.Text);

            if (maxPostOnDay == 0)
            {
                MessageBox.Show("Операция не может быть выполнена - не установлено максимально возможное количетсво постов в день");
                return(false);
            }

            // дата начала
            DateTime startDate;

            if (checkBoxStartFromSelectedDate.Checked)
            {
                if (dateTimePickerBeginDate.Value <= DateTime.Now.AddMinutes(1))
                {
                    MessageBox.Show("Операция не может быть выполнена - дата публикации должна быть минимум + 1 минут к текущему времени/дате");
                    return(false);
                }
                startDate = dateTimePickerBeginDate.Value;
            }
            else
            {
                startDate = DateTime.Now.AddMinutes(1);
            }

            return(true);
        }