Ejemplo n.º 1
0
        public void Producer(object obj)        //игра
        {
            int num = (int)obj;

            System.Timers.Timer timerMove = new System.Timers.Timer();
            model.ListTimers.Add(timerMove);

            try
            {
                timerMove.Interval = 15;
                timerMove.Elapsed += (x, y) => { timerMove_Tick(model.ListMove[num].moveUp, model.ListMove[num].moveDown, model.ListMove[num].moveLeft, model.ListMove[num].moveRight, model.ListMove[num].shift, num); };
                timerMove.Start();

                try
                {
                    while (model.workingServer && model.workingThread)
                    {
                        string tmpString = CTransfers.Reading(model.ListNs[num]);

                        try
                        {
                            SecureQueue.Enqueue(JsonConvert.DeserializeObject <ProcessingServer>(tmpString, CTransfers.jss));
                        }
                        catch
                        {
                            model.ListNs[num].Read(new Byte[2], 0, 2);
                        }

                        manualResetEvent.Set();
                    }
                    timerMove.Stop();
                }
                catch (System.IO.IOException)
                {
                    //ErrorEvent("Отключение игрока в Producer");
                    if (model.ListUsers.Count != 0 && model.ListUsers[num] != null)
                    {
                        model.ListUsers[num].flagShoting = false;
                        lock (model.ListUsers)
                        {
                            model.ListUsers.RemoveAt(num);
                            model.ListUsers.Insert(num, null);
                        }
                    }
                    model.CountGamers -= 1;
                    writingCountGames();
                }
            }
            catch
            {
                //ErrorEvent("Ложный вызов продюсера");
                timerMove.Stop();
            }
        }
Ejemplo n.º 2
0
        public void serverStart()
        {
            TcpListener server = new TcpListener(IPAddress.Any, 1337);

            server.Start();

            TcpClient     client = server.AcceptTcpClient();
            NetworkStream NS     = client.GetStream();

            string TmpText = CTransfers.Reading(NS);

            actual = JsonConvert.DeserializeObject <string>(TmpText);
        }
Ejemplo n.º 3
0
        public void MenuStarting(object tl)        //старт
        {
            TcpClient     tc      = null;
            NetworkStream nStream = null;

            while (model.workingServer)
            {
                try
                {
                    tc = (tl as TcpListener).AcceptTcpClient();
                }
                catch
                {
                    break;
                }

                nStream = tc.GetStream();

                byte[] typeCommand = new byte[1];
                nStream.Read(typeCommand, 0, 1);

                switch (typeCommand[0])
                {
                case 10:
                {
                    string      tmpString = CTransfers.Reading(nStream);
                    GeneralInfo newUser   = JsonConvert.DeserializeObject <GeneralInfo>(tmpString);

                    GeneralInfo tmpUser = ControllersS.cInfoUsers.PlayerCheck(ControllersS.cInfoUsers.PlayerRead(newUser), newUser);
                    if (!model.workingGame)
                    {
                        if (tmpUser == null)
                        {
                            model.ListGInfo.Add(new GeneralInfo());
                            model.ListGInfo[model.ListGInfo.Count - 1].Name     = newUser.Name;
                            model.ListGInfo[model.ListGInfo.Count - 1].Password = newUser.Password;

                            ControllersS.cInfoUsers.PlayerSave(model.ListGInfo);


                            CTransfers.WritingInMenu(model.ListGInfo[model.ListGInfo.Count - 1], 10, nStream);
                        }
                        else
                        {
                            if (ControllersS.cInfoUsers.CheckData(model.ListGInfo, newUser))
                            {
                                model.ListGInfo = ControllersS.cInfoUsers.PlayerRead(newUser);
                                CTransfers.WritingInMenu(tmpUser, 10, nStream);
                            }
                            else
                            {
                                CTransfers.WritingInMenu("1", 11, nStream);
                            }
                            //Если такой игрок уже есть , то при правильном пароле выдать всю инфу об игроке
                        }
                    }
                    else
                    {
                        if (tmpUser == null && model.ListGInfo.Count > 0)
                        {
                            model.ListGInfo.Add(new GeneralInfo());
                            model.ListGInfo[model.ListGInfo.Count - 1].Name     = newUser.Name;
                            model.ListGInfo[model.ListGInfo.Count - 1].Password = newUser.Password;

                            ControllersS.cInfoUsers.PlayerSave(model.ListGInfo);
                            CTransfers.WritingInMenu(model.ListGInfo[model.ListGInfo.Count - 1], 12, nStream);
                        }
                        else
                        {
                            if (ControllersS.cInfoUsers.CheckData(model.ListGInfo, newUser))
                            {
                                model.ListGInfo = ControllersS.cInfoUsers.PlayerRead(newUser);
                                CTransfers.WritingInMenu(tmpUser, 12, nStream);
                            }
                            else
                            {
                                CTransfers.WritingInMenu("1", 12, nStream);
                            }
                        }
                    }
                    break;
                }
                }
                tc.Close();
            }
        }