From d76e12d83e88a6cd83de107da6182a00042e00e8 Mon Sep 17 00:00:00 2001 From: nullptr-w8 Date: Mon, 27 Sep 2021 16:10:13 +0500 Subject: [PATCH] Add WebRender fix fir --- .../Benchmarks/Packets/GumpUtilities.cs | 5 + Projects/Server/Gumps/Gump.cs | 20 +- Projects/Server/Gumps/GumpBody.cs | 27 ++ Projects/Server/Gumps/GumpBodyUpdate.cs | 34 ++ .../Network/Packets/IncomingPlayerPackets.cs | 11 +- .../Network/Packets/OutgoingGumpPackets.cs | 6 + .../Commands/Object Creation/AddGump.cs | 8 +- Projects/UOContent/Gumps/SciterTestGump.cs | 292 ++++++++++++++++++ 8 files changed, 395 insertions(+), 8 deletions(-) create mode 100644 Projects/Server/Gumps/GumpBody.cs create mode 100644 Projects/Server/Gumps/GumpBodyUpdate.cs create mode 100644 Projects/UOContent/Gumps/SciterTestGump.cs diff --git a/Projects/Benchmarks/Benchmarks/Packets/GumpUtilities.cs b/Projects/Benchmarks/Benchmarks/Packets/GumpUtilities.cs index 5df0a12fe..c14ae27a2 100644 --- a/Projects/Benchmarks/Benchmarks/Packets/GumpUtilities.cs +++ b/Projects/Benchmarks/Benchmarks/Packets/GumpUtilities.cs @@ -14,6 +14,11 @@ namespace Server.Tests.Network IGumpWriter disp = new DisplayGumpFast(g); // IGumpWriter disp = new DisplayGumpPacked(g); + if (g.UseWebRender) + { + disp.AppendLayout(Gump.WebRender); + } + if (!g.Draggable) { disp.AppendLayout(Gump.NoMove); diff --git a/Projects/Server/Gumps/Gump.cs b/Projects/Server/Gumps/Gump.cs index cc0940914..29129be0c 100644 --- a/Projects/Server/Gumps/Gump.cs +++ b/Projects/Server/Gumps/Gump.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Text; +using System.Text.Json; using Server.Network; using Server.Text; @@ -8,7 +10,7 @@ namespace Server.Gumps public class Gump { private static Serial _nextSerial = (Serial)1; - + public static readonly byte[] WebRender = StringToBuffer("{ webrender }"); public static readonly byte[] NoMove = StringToBuffer("{ nomove }"); public static readonly byte[] NoClose = StringToBuffer("{ noclose }"); public static readonly byte[] NoDispose = StringToBuffer("{ nodispose }"); @@ -52,6 +54,8 @@ namespace Server.Gumps public bool Closable { get; set; } = true; + public bool UseWebRender { get; set; } = false; + public static int GetTypeID(Type type) => type?.FullName?.GetHashCode(StringComparison.Ordinal) ?? -1; public void AddPage(int page) @@ -68,7 +72,21 @@ namespace Server.Gumps { Add(new GumpBackground(x, y, width, height, gumpID)); } + public void SendData(Mobile m, string responseMethod, object value) + { + Entries.Clear(); + var jtext = JsonSerializer.Serialize(value, new JsonSerializerOptions() { WriteIndented = true }); + Add(new GumpBodyUpdate(responseMethod, + Convert.ToBase64String(Encoding.UTF8.GetBytes(jtext)))); + + m.SendGump(this); + } + + public void AddBody(string body) + { + Add(new GumpBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(body)))); + } public void AddButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type = GumpButtonType.Reply, int param = 0 diff --git a/Projects/Server/Gumps/GumpBody.cs b/Projects/Server/Gumps/GumpBody.cs new file mode 100644 index 000000000..6e8340946 --- /dev/null +++ b/Projects/Server/Gumps/GumpBody.cs @@ -0,0 +1,27 @@ +using Server.Collections; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Gumps +{ + public class GumpBody : GumpEntry + { + public static readonly byte[] LayoutName = Gump.StringToBuffer("body"); + + public override string Compile(OrderedHashSet strings) => $"{{ body {_body} }}"; + public GumpBody(string body) =>_body = body; + public string _body { get; set; } + public override void AppendTo(ref SpanWriter writer, OrderedHashSet strings, ref int entries, ref int switches) + { + writer.Write((ushort)0x7B20); // "{ " + writer.Write(LayoutName); + writer.WriteAscii(' '); + writer.WriteAscii(_body.ToString()); + writer.Write((ushort)0x207D); // " }" + } + } +} diff --git a/Projects/Server/Gumps/GumpBodyUpdate.cs b/Projects/Server/Gumps/GumpBodyUpdate.cs new file mode 100644 index 000000000..6a46e7cc0 --- /dev/null +++ b/Projects/Server/Gumps/GumpBodyUpdate.cs @@ -0,0 +1,34 @@ +using Server.Collections; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Gumps +{ + public class GumpBodyUpdate : GumpEntry + { + public static readonly byte[] LayoutName = Gump.StringToBuffer("bodyUpdate"); + + public override string Compile(OrderedHashSet strings) => $"{{ bodyUpdate {_responseButtonId} {_body} }}"; + public GumpBodyUpdate(string responseButtonId, string body) + { + _body = body; + _responseButtonId = responseButtonId; + } + public string _body { get; set; } + public string _responseButtonId { get; set; } + public override void AppendTo(ref SpanWriter writer, OrderedHashSet strings, ref int entries, ref int switches) + { + writer.Write((ushort)0x7B20); // "{ " + writer.Write(LayoutName); + writer.WriteAscii(' '); + writer.WriteAscii(_responseButtonId); + writer.WriteAscii(' '); + writer.WriteAscii(_body); + writer.Write((ushort)0x207D); // " }" + } + } +} diff --git a/Projects/Server/Network/Packets/IncomingPlayerPackets.cs b/Projects/Server/Network/Packets/IncomingPlayerPackets.cs index 00371638d..9fe375898 100644 --- a/Projects/Server/Network/Packets/IncomingPlayerPackets.cs +++ b/Projects/Server/Network/Packets/IncomingPlayerPackets.cs @@ -349,7 +349,7 @@ namespace Server.Network { continue; } - + var isWebResponse = gump.UseWebRender; var buttonExists = buttonID == 0; // 0 is always 'close' if (!buttonExists) @@ -370,7 +370,7 @@ namespace Server.Network } } - if (!buttonExists) + if (!isWebResponse && !buttonExists) { state.LogInfo("Invalid gump response, disconnecting..."); var exception = new InvalidGumpResponseException($"Button {buttonID} doesn't exist"); @@ -384,7 +384,7 @@ namespace Server.Network var switchCount = reader.ReadInt32(); - if (switchCount < 0 || switchCount > gump.m_Switches) + if (!isWebResponse && (switchCount < 0 || switchCount > gump.m_Switches)) { state.LogInfo("Invalid gump response, disconnecting..."); var exception = new InvalidGumpResponseException($"Bad switch count {switchCount}"); @@ -405,7 +405,7 @@ namespace Server.Network var textCount = reader.ReadInt32(); - if (textCount < 0 || textCount > gump.m_TextEntries) + if (!isWebResponse && (textCount < 0 || textCount > gump.m_TextEntries)) { state.LogInfo("Invalid gump response, disconnecting..."); var exception = new InvalidGumpResponseException($"Bad text entry count {textCount}"); @@ -440,7 +440,8 @@ namespace Server.Network textEntries[i] = new TextRelay(entryID, text); } - state.RemoveGump(gump); + if (!isWebResponse) + state.RemoveGump(gump); var prof = GumpProfile.Acquire(gump.GetType()); diff --git a/Projects/Server/Network/Packets/OutgoingGumpPackets.cs b/Projects/Server/Network/Packets/OutgoingGumpPackets.cs index 8fab20ff2..a314b42cf 100644 --- a/Projects/Server/Network/Packets/OutgoingGumpPackets.cs +++ b/Projects/Server/Network/Packets/OutgoingGumpPackets.cs @@ -108,6 +108,12 @@ namespace Server.Network var layoutWriter = new SpanWriter(_layoutBuffer); + + if (gump.UseWebRender) + { + layoutWriter.Write(Gump.WebRender); + } + if (!gump.Draggable) { layoutWriter.Write(Gump.NoMove); diff --git a/Projects/UOContent/Commands/Object Creation/AddGump.cs b/Projects/UOContent/Commands/Object Creation/AddGump.cs index 84e3523a4..1260d4c30 100644 --- a/Projects/UOContent/Commands/Object Creation/AddGump.cs +++ b/Projects/UOContent/Commands/Object Creation/AddGump.cs @@ -86,10 +86,14 @@ namespace Server.Gumps (m_Page + 1) * 10 < searchResults.Length ? 0x7FFF : 0x5EF7 ); } - - public static void Initialize() + private static void Sciter_OnCommand(CommandEventArgs e) + { + e.Mobile.SendGump(new SciterTestGump(e.Mobile)); + } + public static void Initialize() { CommandSystem.Register("AddMenu", AccessLevel.GameMaster, AddMenu_OnCommand); + CommandSystem.Register("t", AccessLevel.GameMaster, Sciter_OnCommand); } [Usage("AddMenu [searchString]"), Description( diff --git a/Projects/UOContent/Gumps/SciterTestGump.cs b/Projects/UOContent/Gumps/SciterTestGump.cs new file mode 100644 index 000000000..ce6b87a43 --- /dev/null +++ b/Projects/UOContent/Gumps/SciterTestGump.cs @@ -0,0 +1,292 @@ +using Server.Gumps; +using Server.Network; +using System; +using System.IO; +using System.Text; + +namespace Server.Gumps +{ + public class SciterTestGump : Gump + { + public class Shop + { + public string[] ShopItems { get; set; } = new string[] { "item1", "item2" }; + } + + public SciterTestGump(Mobile user) : base( + 0, + 0 + ) + { + UseWebRender = true; + AddBody(Body()); + } + + public override void OnResponse(NetState sender, RelayInfo info) + { + var from = sender.Mobile; + switch (info.ButtonID) + { + case 0: // close + sender.RemoveGump(this); + break; + case 1: // hide + from.Hidden = true; + break; + case 2: // unhide + from.Hidden = false; + break; + case 3: // sendDataToCLeint + SendData(from, "ShowSend", new Shop()); + break; + case 4: // showData + var builder = new StringBuilder(); + for (int i = 0; i < info.TextEntries.Length; i++) + { + var test = info.TextEntries[i].Text; + builder.Append("argument "); + builder.Append(i.ToString()); + builder.Append(" = "); + builder.Append(test); + builder.Append(" "); + } + + from.SendAsciiMessage(builder.ToString()); + + break; + default: + break; + + + } + } + public string Body() + { + return "\r\n" + + " \r\n" + + " Test<" + + "/title>\r\n" + + " <style>\r\n" + + " [onmousele" + + "ave] { aspect: \"Emu" + + ".onmouseleave\"; }\r" + + "\n" + + " html {\r" + + "\n" + + " over" + + "flow: hidden;\r\n" + + " \r\n" + + " }\r\n" + + " \r\n" + + " .btn {\r\n" + + " border: 2px solid " + + "black;\r\n" + + " border-radius: 5px" + + ";\r\n" + + " background-color: " + + "white;\r\n" + + " color: black;\r\n" + + " padding: 14px 28px" + + ";\r\n" + + " font-size: 16px;\r" + + "\n" + + " cursor: pointer;\r" + + "\n" + + "} \r\n" + + ".success {\r\n" + + " border-color: #04A" + + "A6D;\r\n" + + " color: green;\r\n" + + "}\r\n\r\n" + + ".success:hover {\r\n" + + " background-color: " + + "#04AA6D;\r\n" + + " color: white;\r\n" + + "}\r\n\r\n" + + "/* Blue */\r\n" + + ".info {\r\n" + + " border-color: #219" + + "6F3;\r\n" + + " color: dodgerblue" + + "\r\n" + + "}\r\n\r\n" + + ".info:hover {\r\n" + + " background: #2196F" + + "3;\r\n" + + " color: white;\r\n" + + "}\r\n\r\n" + + "/* Orange */\r\n" + + ".warning {\r\n" + + " border-color: #ff9" + + "800;\r\n" + + " color: orange;\r\n" + + "}\r\n\r\n" + + ".warning:hover {\r\n" + + " background: #ff980" + + "0;\r\n" + + " color: white;\r\n" + + "}\r\n\r\n" + + "/* Red */\r\n" + + ".danger {\r\n" + + " border-color: #f44" + + "336;\r\n" + + " color: red\r\n" + + "}\r\n\r\n" + + ".danger:hover {\r\n" + + " background: #f4433" + + "6;\r\n" + + " color: white;\r\n" + + "}\r\n\r\n" + + "/* Gray */\r\n" + + ".default {\r\n" + + " border-color: #e7e" + + "7e7;\r\n" + + " color: black;\r\n" + + "}\r\n\r\n" + + ".default:hover {\r\n" + + " background: #e7e7e" + + "7;\r\n" + + "}\r\n\r\n" + + " </style>\r\n" + + " <script type=\"t" + + "ext/tiscript\">\r\n" + + "\r\n" + + " namespace Em" + + "u {\r\n" + + " function o" + + "nmouseleave() {\r\n" + + " this.o" + + "n(\"mouseleave\", fu" + + "nction(evt) {\r\n" + + " \r\n" + + " });\r" + + "\n" + + " }\r\n" + + " }\r\n\r\n" + + " function sel" + + "f.ready() {\r\n" + + " view.move(" + + "400px,100px,500,300)" + + ";\r\n" + + " view.windo" + + "wTopmost = false;\r" + + "\n" + + " //focus on" + + " form \r\n" + + " //this.tim" + + "er(20ms, function() " + + "{ view.focusable(#fi" + + "rst).state.focus = t" + + "rue; });\r\n" + + " }\r\n\r\n" + + " self.on(\"ke" + + "ydown\", function(ev" + + "t) {\r\n" + + " if(evt.ke" + + "yCode == 27)\r\n" + + " {\r\n" + + " close(" + + ");\r\n" + + " }\r\n" + + " });\r\n\r\n" + + " function Sho" + + "wSend(data)\r\n" + + " {\r\n" + + " var input " + + "= $(#test);\r\n" + + " if(element" + + ")return; \r\n" + + " input.clea" + + "r();\r\n\r\n" + + " for (var i" + + " = 0; i < data.ShopI" + + "tems.length; i++) {" + + "\r\n" + + " input.ap" + + "pend(data.ShopItems[" + + "i]+\' ,\');\r\n" + + " }\r\n" + + " }\r\n\r\n" + + " function clo" + + "se()\r\n" + + " {\r\n" + + " view.Host_" + + "SEND(0);\r\n" + + " view.windo" + + "wState = View.WINDOW" + + "_HIDDEN;\r\n" + + " view.move(" + + "0px,0px,0,0);\r\n" + + " }\r\n" + + " \r\n\r\n\r\n" + + " event click " + + "$(button#load) {\r\n" + + " view.Hos" + + "t_SEND(3);\r\n" + + " }\r\n\r\n" + + " event click " + + "$(button#send) {\r\n" + + " view.Hos" + + "t_SEND(4,\"arg0\",\"" + + "arg1\",\"arg2\",\"ar" + + "g3\",\"arg4\",\"arg5" + + "\",\"arg6\",\"arg7\"" + + ",\"arg8\",\"arg9\");" + + "\r\n" + + " }\r\n\r\n" + + " event click " + + "$(button#hide) {\r\n" + + " view.Hos" + + "t_SEND(1,\"HELLO WOR" + + "LD YEAH\");\r\n" + + " }\r\n\r\n" + + " event click " + + "$(button#unhide) {\r" + + "\n" + + " view.Hos" + + "t_SEND(2);\r\n" + + " }\r\n\r\n" + + " event click " + + "$(button#close) {\r" + + "\n" + + " close();\r" + + "\n" + + " }\r\n" + + " \r\n\r\n" + + " </script>\r\n" + + " \r\n" + + " </head>\r\n" + + " <body onmouselea" + + "ve>\r\n" + + " <button#load" + + " class=\"btn warning" + + "\" onmouseenter onmo" + + "useleave>getDataFrom" + + "Server</button>\r\n" + + " <button#send" + + " class=\"btn warning" + + "\" onmouseenter onmo" + + "useleave>sendDataToS" + + "erver</button>\r\n" + + " <button#hide" + + " class=\"btn warning" + + "\" onmouseenter onmo" + + "useleave>hide</butto" + + "n>\r\n" + + " <button#unhi" + + "de class=\"btn info" + + "\">unhide</button>\r" + + "\n" + + " <button#clos" + + "e class=\"btn danger" + + "\">Close</button>\r" + + "\n" + + " <textarea id" + + "=\"test\" name=\"com" + + "ment\"></textarea></" + + "p>\r\n" + + " </body>\r\n" + + "</html>"; + } + } +}