private IRestResponse SendRequest(Me me, IPAddress ip, int port, HttpMethod post, bool sendPicture = false) { SendableMe meSendable = new SendableMe().ConvertFromMe(me); string meSendableJSON = JsonConvert.SerializeObject(meSendable); string base64Image = ""; if (sendPicture && AmeisenDataHolder.Settings.picturePath.Length > 0) { base64Image = Convert.ToBase64String( Utils.ImageToByte( new Bitmap(AmeisenDataHolder.Settings.picturePath))); } RestClient client = new RestClient($"http://{ip}:{port}"); // client.Authenticator = new HttpBasicAuthenticator(username, password); RestRequest request = new RestRequest("bot/{name}", Method.PUT) { RequestFormat = DataFormat.Json }; request.AddUrlSegment("name", AmeisenDataHolder.Settings.ameisenServerName); request.AddParameter("id", 0); request.AddParameter("ip", "0.0.0.0"); request.AddParameter("lastActive", Environment.TickCount); request.AddParameter("name", AmeisenDataHolder.Settings.ameisenServerName); request.AddParameter("me", meSendableJSON); request.AddParameter("picture", base64Image); return(client.Execute(request)); }
private static int UpdateBot(HttpListenerRequest request) { string bodyContent = ReadBody(request); int idToUpdate = Convert.ToInt32(bodyContent.Split(']')[0].Replace("]", "")); string botContent = bodyContent.Split(']')[1]; SendableMe meSendable = JsonConvert.DeserializeObject <SendableMe>(botContent); NetworkBot convertedBot = new NetworkBot { id = idToUpdate, me = meSendable, ip = request.RemoteEndPoint.Address.ToString(), base64Image = ((NetworkBot)activeBots[GetBotPositionByID(idToUpdate)]).base64Image, lastUpdate = DateTimeOffset.Now.ToUnixTimeMilliseconds() }; convertedBot.name = convertedBot.me.Name; activeBots[GetBotPositionByID(idToUpdate)] = convertedBot; return(idToUpdate); }
private void UIUpdateTimer_Tick(object sender, EventArgs e) { if (BotManager.IsRegisteredAtServer) { botViewPanel.Children.Clear(); List <NetworkBot> networkBots = BotManager.NetworkBots; if (networkBots != null) { foreach (NetworkBot bot in networkBots) { BotView botView = new BotView(); SendableMe me = bot.GetMe(); botView.botName.Content = me.Name; botView.botLevel.Content = me.Level; botView.botHealth.Content = $"{me.Health} / {me.MaxHealth}"; botView.botEnergy.Content = $"{me.Energy} / {me.MaxEnergy}"; botView.botExp.Content = $"{me.Exp} / {me.MaxExp}"; botView.botHealthProgressbar.Maximum = me.MaxHealth; botView.botEnergyProgressbar.Maximum = me.MaxEnergy; botView.botExpProgressbar.Maximum = me.MaxExp; botView.botHealthProgressbar.Value = me.Health; botView.botEnergyProgressbar.Value = me.Energy; botView.botExpProgressbar.Value = me.Exp; if (bot.picture != "") { botView.botImage.Source = Utils.Base64ToBitmapImage(bot.picture); } botViewPanel.Children.Add(botView); } } } }
public NetworkRegData(string base64Image, SendableMe me) { Me = me; Base64Image = base64Image; }