Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- namespace Fps_Server
- {
- public class SignalClass
- {
- private Main_Form MainForm;
- public bool Command = false;
- public bool Ready = false;
- public SignalClass(Main_Form Main)
- {
- MainForm = Main;
- }
- public byte[] Signal;
- public IPAddress IP = IPAddress.Parse("192.168.105.182");
- public void S2M()
- {
- Message = ASCIIEncoding.ASCII.GetString(Signal);
- }
- public string Message
- {
- set
- {
- if (value != "")
- {
- List<char> CharList = value.ToList<char>();
- if (CharList[0] == char.Parse("/"))
- {
- Command = true;
- CharList.RemoveAt(0);
- }
- value = string.Join("", CharList);
- }
- for (int i = 0; i < value.Length; i++)
- {
- if (char.IsWhiteSpace(value[i]) && value[i] != char.Parse(" "))
- {
- value = value.Remove(i);
- }
- }
- MessageArray = value.Split(new char[] { char.Parse(" ") });
- foreach (string M in MessageArray)
- {
- if (M.Contains(char.Parse(":")) || M.Contains(char.Parse(";")))
- {
- string[] Ma = M.Split(new char[] { char.Parse(":"), char.Parse(";") });
- if (Ma.Length > 2)
- {
- string Ma1 = "";
- for (int i = 1; i < Ma.Length; i++)
- {
- Ma1 += Ma[i];
- if (i + 1 < Ma.Length)
- {
- Ma1 += ":";
- }
- }
- Ma = new string[2]
- {
- Ma[0],
- Ma1
- };
- }
- Ma = CommandsConverter(Ma);
- if (Ma[1].Contains(char.Parse("_")))
- {
- bool FirstTime = true;
- string[] UnderScoreSplit = Ma[1].Split(new char[] { char.Parse("_") });
- Ma[1] = string.Empty;
- foreach (string S in UnderScoreSplit)
- {
- if (FirstTime)
- {
- FirstTime = false;
- Ma[1] += S;
- }
- else
- {
- Ma[1] += " " + S;
- }
- }
- }
- try
- {
- MessageDictionary.Add(Ma[0], Ma[1]);
- }
- catch (Exception e)
- {
- if (e.InnerException is ArgumentException)
- {
- try
- {
- MessageDictionary.Add(Ma[0], Ma[1]);
- }
- catch (Exception ex)
- {
- MainForm.ConsoleWriter(ex);
- }
- }
- }
- }
- }
- }
- }
- private string[] CommandsConverter(string[] Ma)
- {
- string Ma0 = Ma[0];
- if (Ma0 == "A")
- {
- Ma0 = "Action";
- }
- else if (Ma0 == "V")
- {
- Ma0 = "Value";
- }
- else if (Ma0 == "P")
- {
- Ma0 = "Port";
- }
- else if (Ma0 == " ")
- {
- Ma0 = "Action";
- }
- else if (Ma0 == " ")
- {
- Ma0 = "Action";
- }
- else if (Ma0 == " ")
- {
- Ma0 = "Action";
- }
- Ma[0] = Ma0;
- return Ma;
- }
- public string[] MessageArray;
- public Dictionary<string, string> MessageDictionary = new Dictionary<string,string>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment