Esempio n. 1
0
        public static void _for_new_user(AllUser AllPlayer, IPEndPoint remoteEP)
        {
            int id = AllPlayer._new_user();

            byte[] msg = Encoding.ASCII.GetBytes(AllPlayer.AllUser_database[id - 1].Authorization());
            ReceiverUDP.udpServer.Send(msg, msg.Length, remoteEP);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            AllUser AllPlayer = new AllUser();
            AllPrey AllPrey   = new AllPrey();

            ReceiverUDP.Receiver(localPort, AllPlayer, AllPrey);
        }
Esempio n. 3
0
        private static void _AppendPrey(string[] str_com, IPEndPoint remoteEP, AllUser AllPlayer)
        {
            UserClient _one_user = new UserClient(str_com[4], str_com[5], Convert.ToInt32(str_com[3]));
            Prey       _one_prey = new Prey(str_com[1], str_com[2]);
            bool       notfound  = false;

            foreach (var _user in AllPlayer.AllUser_database)
            {
                if (_CompareUser(_user, _one_user))
                {
                    foreach (var _prey in AllPrey.AllPrey_database)
                    {
                        if (_ComparePrey(_prey, _one_prey))
                        {
                            _user._all_sacrifice.Add(_prey);
                            Console.WriteLine("[append_prey][OK]");
                            byte[] msg = BaseTools.Convertbtst("[append_prey][OK]");
                            ReceiverUDP.udpServer.Send(msg, msg.Length, remoteEP);
                            AllPlayer._SavePrey(_prey, _user);
                            notfound = true;
                            break;
                        }
                    }

                    break;
                }
            }
            if (!notfound)
            {
                byte[] btnotfound = BaseTools.Convertbtst("[append_prey][not found]");
                ReceiverUDP.udpServer.Send(btnotfound, btnotfound.Length, remoteEP);
            }
        }
Esempio n. 4
0
        public static void _OtherCommand(AllUser AllPlayer, IPEndPoint remoteEP, string[] mas)
        {
            UserClient _client = new UserClient(mas[2], mas[1], Convert.ToInt32(mas[0]));

            switch (mas[3])
            {
            case "get_all_sacrifice":
                _SearchUserInBase(AllPlayer, remoteEP, ref _client);
                break;

            default:
                Console.WriteLine(string.Join("", mas));
                break;
            }
        }
Esempio n. 5
0
        public static void Receiver(int localPort, AllUser AllPlayer, AllPrey AllPrey)
        {
            Console.WriteLine("Whait connect\n");
            udpServer = new UdpClient(localPort);
            var outer = Task.Factory.StartNew(() => BaseTools._Cheak_online_Prey(AllPrey));

            while (true)
            {
                var remoteEP = new IPEndPoint(IPAddress.Any, 19999);

                var data = udpServer.Receive(ref remoteEP);
                Console.WriteLine("Подключен " + remoteEP.Address + ":" + remoteEP.Port + " --> " + BaseTools.Convertbtst(data));
                Command._start_command(data, remoteEP, AllPlayer, AllPrey);
            }
        }
Esempio n. 6
0
 public static void _SearchUserInBase(AllUser AllPlayer, IPEndPoint remoteEP, ref UserClient _client)
 {
     foreach (var _user in AllPlayer.AllUser_database)
     {
         if (_CompareUser(_user, _client))
         {
             _user._now_ip_port     = remoteEP;
             _client._now_ip_port   = remoteEP;
             _client._all_sacrifice = _user._all_sacrifice;
             _client.online         = true;
             string allSacrifice = "[get_all_sacrifice]" + _client._AllSacrificeToString();
             byte[] com          = BaseTools.Convertbtst(allSacrifice);
             ReceiverUDP.udpServer.Send(com, com.Length, remoteEP);
         }
     }
 }
Esempio n. 7
0
        public static void _start_command(byte[] command, IPEndPoint remoteEP, AllUser AllPlayer, AllPrey AllPrey)
        {
            string str_command = BaseTools.Convertbtst(command);

            string[] mas_com = str_command.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);


            switch (mas_com[0])
            {
            case "ping_1":
                _for_ping(remoteEP);
                break;

            case "0":
                _for_new_user(AllPlayer, remoteEP);
                break;

            case "prey_get_token":
                _RegistrNewPrey(mas_com, remoteEP, AllPrey);
                break;

            case "prey_online":
                _ForPreyOnline(mas_com, remoteEP);
                break;

            case "append_prey":
                _AppendPrey(mas_com, remoteEP, AllPlayer);
                break;

            case "need_prey":
                _NeedPrey(mas_com, remoteEP, AllPrey);
                break;

            default:
                _OtherCommand(AllPlayer, remoteEP, mas_com);
                break;
            }
        }