static async Task RunAsync() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:4810//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // HTTP POST var command = new Command() { Id = Guid.NewGuid(), Name = "My Name is Pepper" }; HttpResponseMessage response = await client.PostAsJsonAsync("api/command", command); if (response.IsSuccessStatusCode) { Console.WriteLine("Sucsesfully posted a command"); } } }
/// <summary> /// Register a new command /// </summary> /// <param name="Name">Name of command</param> /// <param name="command">What is supposed to be ran</param> public static void RegisterCommand(string Name, Command command) { Core.DebugLog("Registering a new command by extension: " + Name); lock (commands) { commands.Add(Name, command); } }
private bool CheckExpressions(Message message, Command command) { foreach (var regex in command.Expressions) { if (regex.Match(message.Content).Success) return true; } return false; }
//Converts the bytes into an object of type Data public Data(byte[] data) { //Index to keep track of positioning int index = 0; //The first four bytes are for the Command this.cmdCommand = (Command)BitConverter.ToInt32(data, index); index = index + 4; //Number of players this.playerCount = BitConverter.ToInt32(data, index); index = index + 4; //player ID this.playerID = BitConverter.ToInt32(data, index); index = index + 4; //For each player, get ship data for (int i = 0; i <= playerCount - 1; i++) { shipList[i].SetX(BitConverter.ToInt32(data, index)); index = index + 4; shipList[i].SetY(BitConverter.ToInt32(data, index)); index = index + 4; shipList[i].SetAngle(BitConverter.ToInt32(data, index)); index = index + 4; } //Number of planets this.planetCount = BitConverter.ToInt32(data, index); index = index + 4; //For each planet get data for (int m = 0; m < planetCount; m++) { planetList[m].SetX(BitConverter.ToInt32(data, index)); index = index + 4; planetList[m].SetY(BitConverter.ToInt32(data, index)); index = index + 4; model.Update(planetList[m]); } //The next four store the length of the nickname int nameLen = BitConverter.ToInt32(data, index); index = index + 4; //The next four store the length of the message int msgLen = BitConverter.ToInt32(data, index); index = index + 4; //This gets the name or sets it as null. if (nameLen > 0) this.strName = Encoding.UTF8.GetString(data, index, nameLen); else { this.strName = null; index = index + 4; } //This gets the message or sets it as null if (msgLen > 0) this.strMessage = Encoding.UTF8.GetString(data, index + nameLen, msgLen); else { this.strMessage = null; index = index + 4; } //update index index = index + nameLen + msgLen; //Get the number of bullets this.bulletCount = BitConverter.ToInt32(data, index); index = index + 4; //For each bullet, remove them all (redraw them in their new position. //TODO: Review this //Note: this may not be the best way of doing things, but is needed so bullets don't mess up currently. for (int n = bulletCount; n < bulletList.Count(); n++) { model.Remove(20 + n); bulletList.RemoveAt(n); } //Readd all the bullets to the model for (int j = 0; j < bulletCount; j++) { int exists = 0; //If the bullets already exist, do nothing foreach (GraphicsObject g in bulletList) { if (g.GetID() == (20 + j)) { //do nothing exists = 1; break; } } //If they don't, create a bullet and add it to the list. if (exists == 0) { bulletList.Add(new GraphicsObject(20 + j, 0, 0, 4, 0, 102, 1)); } bulletList[j].SetX(BitConverter.ToInt32(data, index)); index = index + 4; bulletList[j].SetY(BitConverter.ToInt32(data, index)); index = index + 4; model.Update(bulletList[j]); }//End for loop }
public string strName; //Name by which the client logs into the room #endregion Fields #region Constructors //Default constructor public Data() { this.cmdCommand = Command.Null; this.strMessage = null; this.strName = null; }