diondokter

Old Horrible SignalClass

Jun 20th, 2015
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7.  
  8. namespace Fps_Server
  9. {
  10.     public class SignalClass
  11.     {
  12.         private Main_Form MainForm;
  13.  
  14.         public bool Command = false;
  15.         public bool Ready = false;
  16.  
  17.         public SignalClass(Main_Form Main)
  18.         {
  19.             MainForm = Main;
  20.         }
  21.  
  22.         public byte[] Signal;
  23.     public IPAddress IP = IPAddress.Parse("192.168.105.182");
  24.  
  25.         public void S2M()
  26.         {
  27.             Message = ASCIIEncoding.ASCII.GetString(Signal);
  28.         }
  29.  
  30.         public string Message
  31.         {
  32.             set
  33.             {
  34.                 if (value != "")
  35.                 {
  36.                     List<char> CharList = value.ToList<char>();
  37.                     if (CharList[0] == char.Parse("/"))
  38.                     {
  39.                         Command = true;
  40.                         CharList.RemoveAt(0);
  41.                     }
  42.                     value = string.Join("", CharList);
  43.                 }
  44.  
  45.         for (int i = 0; i < value.Length; i++)
  46.         {
  47.             if (char.IsWhiteSpace(value[i]) && value[i] != char.Parse(" "))
  48.             {
  49.                 value = value.Remove(i);
  50.             }
  51.         }
  52.  
  53.                 MessageArray = value.Split(new char[] { char.Parse(" ") });
  54.         foreach (string M in MessageArray)
  55.         {
  56.             if (M.Contains(char.Parse(":")) || M.Contains(char.Parse(";")))
  57.             {
  58.                 string[] Ma = M.Split(new char[] { char.Parse(":"), char.Parse(";") });
  59.                 if (Ma.Length > 2)
  60.                 {
  61.                     string Ma1 = "";
  62.                     for (int i = 1; i < Ma.Length; i++)
  63.                     {
  64.                         Ma1 += Ma[i];
  65.                         if (i + 1 < Ma.Length)
  66.                         {
  67.                             Ma1 += ":";
  68.                         }
  69.                     }
  70.                     Ma = new string[2]
  71.                     {
  72.                         Ma[0],
  73.                         Ma1
  74.                     };
  75.                 }
  76.  
  77.                 Ma = CommandsConverter(Ma);
  78.  
  79.                 if (Ma[1].Contains(char.Parse("_")))
  80.                 {
  81.                     bool FirstTime = true;
  82.                     string[] UnderScoreSplit = Ma[1].Split(new char[] { char.Parse("_") });
  83.                     Ma[1] = string.Empty;
  84.                     foreach (string S in UnderScoreSplit)
  85.                     {
  86.                         if (FirstTime)
  87.                         {
  88.                             FirstTime = false;
  89.                             Ma[1] += S;
  90.                         }
  91.                         else
  92.                         {
  93.                             Ma[1] += " " + S;
  94.                         }
  95.                     }
  96.                 }
  97.  
  98.                 try
  99.                 {
  100.                     MessageDictionary.Add(Ma[0], Ma[1]);
  101.                 }
  102.                 catch (Exception e)
  103.                 {
  104.                     if (e.InnerException is ArgumentException)
  105.                     {
  106.                         try
  107.                         {
  108.                             MessageDictionary.Add(Ma[0], Ma[1]);
  109.                         }
  110.                         catch (Exception ex)
  111.                         {
  112.                             MainForm.ConsoleWriter(ex);
  113.                         }
  114.                     }
  115.                 }
  116.             }
  117.         }
  118.             }
  119.         }
  120.  
  121.         private string[] CommandsConverter(string[] Ma)
  122.         {
  123.             string Ma0 = Ma[0];
  124.  
  125.             if (Ma0 == "A")
  126.             {
  127.                 Ma0 = "Action";
  128.             }
  129.             else if (Ma0 == "V")
  130.             {
  131.                 Ma0 = "Value";
  132.             }
  133.             else if (Ma0 == "P")
  134.             {
  135.                 Ma0 = "Port";
  136.             }
  137.             else if (Ma0 == " ")
  138.             {
  139.                 Ma0 = "Action";
  140.             }
  141.             else if (Ma0 == " ")
  142.             {
  143.                 Ma0 = "Action";
  144.             }
  145.             else if (Ma0 == " ")
  146.             {
  147.                 Ma0 = "Action";
  148.             }
  149.  
  150.             Ma[0] = Ma0;
  151.  
  152.             return Ma;
  153.         }
  154.  
  155.         public string[] MessageArray;
  156.         public Dictionary<string, string> MessageDictionary = new Dictionary<string,string>();
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment