Compare commits

...
Sign in to create a new pull request.

12 commits

Author SHA1 Message Date
Kamron Batman
217c63a07a
Merge branch 'main' into webSupport
# Conflicts:
#	Projects/Benchmarks/Benchmarks/Packets/GumpUtilities.cs
#	Projects/Server/Gumps/Gump.cs
#	Projects/Server/Network/Packets/IncomingPlayerPackets.cs
#	Projects/Server/Network/Packets/OutgoingGumpPackets.cs
2022-07-08 16:09:07 -07:00
Kamron Batman
f0471f35f8
Merge branch 'main' into webSupport 2022-01-06 12:20:03 -08:00
Kamron Batman
f5fef07e0c
Merge branch 'main' into webSupport 2021-12-24 16:02:16 -08:00
Kamron Batman
3650878399
Merge branch 'main' into webSupport 2021-12-04 23:43:12 -08:00
Kamron Batman
a3458a2950
Merge branch 'main' into webSupport 2021-11-21 18:18:51 -08:00
Kamron Batman
1f81bb7303
Merge branch 'main' into webSupport 2021-11-12 08:47:32 -08:00
Kamron Batman
8e79abc243
Merge branch 'main' into webSupport 2021-10-12 00:04:57 -07:00
Kamron Batman
d3c313e8a4
Merge branch 'main' into webSupport 2021-10-05 09:08:44 -07:00
Kamron Batman
e933198a85
Merge branch 'main' into webSupport 2021-10-04 15:31:43 -07:00
Kamron Batman
51e73a0f90
Merge branch 'main' into webSupport 2021-09-30 10:23:45 -07:00
nullptr-w8
af7ce57d89 demo sciter-js 2021-09-30 16:15:44 +05:00
nullptr-w8
d76e12d83e Add WebRender
fix

fir
2021-09-27 16:32:14 +05:00
7 changed files with 388 additions and 6 deletions

View file

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using Server.Network;
using Server.Text;
using Server.Utilities;
@ -10,6 +12,7 @@ public partial 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 }");
@ -53,6 +56,8 @@ public partial class Gump
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)
@ -70,6 +75,22 @@ public partial class Gump
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

View file

@ -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<string> strings) => $"{{ body {_body} }}";
public GumpBody(string body) =>_body = body;
public string _body { get; set; }
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(_body.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -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<string> 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<string> 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); // " }"
}
}
}

View file

@ -350,6 +350,7 @@ public static class IncomingPlayerPackets
continue;
}
var isWebResponse = gump.UseWebRender;
var buttonExists = buttonID == 0; // 0 is always 'close'
if (!buttonExists)
@ -370,7 +371,7 @@ public static class IncomingPlayerPackets
}
}
if (!buttonExists)
if (!isWebResponse && !buttonExists)
{
state.LogInfo("Invalid gump response, disconnecting...");
var exception = new InvalidGumpResponseException($"Button {buttonID} doesn't exist");
@ -384,7 +385,7 @@ public static class IncomingPlayerPackets
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 +406,7 @@ public static class IncomingPlayerPackets
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 +441,10 @@ public static class IncomingPlayerPackets
textEntries[i] = new TextRelay(entryID, text);
}
if (!isWebResponse)
{
state.RemoveGump(gump);
}
var prof = GumpProfile.Acquire(gump.GetType());

View file

@ -109,6 +109,11 @@ public static class OutgoingGumpPackets
var layoutWriter = new SpanWriter(_layoutBuffer);
if (gump.UseWebRender)
{
layoutWriter.Write(Gump.WebRender);
}
if (!gump.Draggable)
{
layoutWriter.Write(Gump.NoMove);

View file

@ -86,10 +86,14 @@ namespace Server.Gumps
(m_Page + 1) * 10 < searchResults.Length ? 0x7FFF : 0x5EF7
);
}
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]")]

View file

@ -0,0 +1,287 @@
using Server.Gumps;
using Server.Items;
using Server.Network;
using System;
using System.IO;
using System.Text;
namespace Server.Gumps
{
public class SciterTestGump : Gump
{
public class Item
{
public string Name { get; set; }
public int Count { get; set; }
}
public class Shop
{
public Item[] ShopItems { get; set; } = new Item[]
{
new Item(){Name="Arrow",Count = 10 },
new Item(){Name="Bolt",Count = 10 },
new Item(){Name="Gold",Count = 20000 },
};
}
public Shop _shop = new Shop();
public SciterTestGump(Mobile user) : base(
0,
0
)
{
UseWebRender = true;
AddBody(body());
}
public void TryToAddItem(Mobile m, int index)
{
if (_shop.ShopItems.Length < index)
return;
var itemName = _shop.ShopItems[index].Name;
var itemCount = Convert.ToInt32(_shop.ShopItems[index].Count);
var type = AssemblyHandler.FindTypeByName(itemName);
var item = Activator.CreateInstance(type, args: new object[] { itemCount });
if (item is Server.Item _item)
{
m.AddToBackpack(_item);
}
}
public override void OnResponse(NetState sender, RelayInfo info)
{
var from = sender.Mobile;
switch (info.ButtonID)
{
case 0: // close
sender.RemoveGump(this);
break;
case 1:
SendData(from, "1", _shop);
break;
case 2:
TryToAddItem(from, Convert.ToInt32(info.TextEntries[0].Text));
break;
default:
break;
}
}
public string body()
{
return "<html >\r\n" +
" \r\n" +
" <style>\r\n" +
" html{backgroun" +
"d-color:black}\r\n" +
" h1 { color: wh" +
"ite;}\r\n" +
" p{color: white" +
";}\r\n" +
" .btn1 {\r\n" +
" backgrou" +
"nd-color: yellow;\r" +
"\n" +
" color: b" +
"lack;\r\n" +
" text-ali" +
"gn: center;\r\n" +
" font-siz" +
"e: 13px;\r\n" +
" }\r\n" +
" #close {\r\n" +
" position: re" +
"lative;\r\n" +
" float: right" +
";\r\n" +
" \r\n" +
" }\r\n" +
" \r\n" +
" .center {\r\n" +
" position: re" +
"lative;\r\n" +
" float: cente" +
"r;\r\n" +
" } \r\n" +
" \r\n" +
" .close-btn {\r" +
"\n" +
" font-size: 6" +
"0px;\r\n" +
" font-weight:" +
" bold;\r\n" +
" color: #000;" +
"\r\n" +
" }\r\n" +
" .tsize\r\n" +
" {\r\n" +
" color: r" +
"ed;\r\n" +
" font-siz" +
"e: 18px;\r\n" +
" }\r\n" +
" .myButton " +
"{\r\n" +
" box-shadow" +
":inset 0px 34px 0px " +
"-15px #b54b3a;\r\n" +
" background" +
":linear-gradient(to " +
"bottom, #a73f2d 5%, " +
"#b34332 100%);\r\n" +
" background" +
"-color:#a73f2d;\r\n" +
" border:1px" +
" solid #241d13;\r\n" +
" display:in" +
"line-block;\r\n" +
" cursor:poi" +
"nter;\r\n" +
" color:#fff" +
"fff;\r\n" +
" font-famil" +
"y:Arial;\r\n" +
" font-size:" +
"15px;\r\n" +
" font-weigh" +
"t:bold;\r\n" +
" padding:9p" +
"x 23px;\r\n" +
" text-decor" +
"ation:none;\r\n" +
" text-shado" +
"w:0px -1px 0px #7a2a" +
"1d;\r\n" +
" }\r\n" +
" .myButton:ho" +
"ver {\r\n" +
" background" +
":linear-gradient(to " +
"bottom, #b34332 5%, " +
"#a73f2d 100%);\r\n" +
" background" +
"-color:#b34332;\r\n" +
" }\r\n" +
" .myButton:ac" +
"tive {\r\n" +
" position:r" +
"elative;\r\n" +
" top:1px;\r" +
"\n" +
" }\r\n" +
" </style>\r\n" +
" \r\n\r\n" +
"\t<script type=\"mod" +
"ule\">\r\n\r\n" +
"\t\tdocument.ready =" +
" function () {\r\n" +
"\t\t}\r\n" +
" \r\n" +
" document.onmouse" +
"leave = function(){" +
"\r\n" +
" Window.this.xc" +
"all(\"GameFocus\");" +
"\r\n" +
" }\r\n" +
"\t</script>\r\n" +
" \r\n" +
"</head>\r\n" +
" <body>\r\n" +
" <div id=\"app\" " +
">\r\n" +
" <a id=\"clos" +
"e\" v-on:click=\"Clo" +
"se()\" class=\"tsize" +
"\">&#x2715;</a>\r\n" +
" <h1 class=\"" +
"center\"> MUO + VueJ" +
"s Demo</h1>\r\n" +
" <ul>\r\n" +
" <li v-for=\"" +
"(item, index) in sho" +
"pItems\">\r\n" +
" <p>{{ item" +
".Name }} amount: {{ " +
"item.Count }} \r\n" +
" <a href=" +
"\"#\" class=\"myButt" +
"on\" v-on:click=\"Ge" +
"t(index)\">OK</a>\r" +
"\n" +
" </p>\r\n" +
" </li>\r\n" +
" </ul>\r\n" +
" </div>\r\n" +
" <script src=\"http" +
"s://unpkg.com/vue\">" +
"</script>\r\n" +
" <!-- <script src=" +
"\"js\\vue.js\"></scr" +
"ipt> -->\r\n" +
" <script>\r\n" +
" var app = new " +
"Vue({\r\n" +
" el: \'#app" +
"\',\r\n" +
" data: {\r" +
"\n" +
" shopI" +
"tems: []\r\n" +
" },\r\n" +
" beforeMoun" +
"t(){\r\n" +
" //set s" +
"ize \r\n" +
" Window." +
"this.move(100,100, 5" +
"00, 500, false);\r\n" +
" this.ge" +
"tItems();\r\n" +
" },\r\n" +
" methods: {" +
"\r\n" +
" getItems" +
": function () {\r\n" +
" Window" +
".this.xcall(\"SEND\"" +
", 1 ,function (value" +
") {\r\n" +
" //" +
"you can\'t use this " +
"now it\'s func\r\n" +
" ap" +
"p.shopItems = value." +
"ShopItems;\r\n" +
"\t\t\t });\r" +
"\n" +
" },\r\n" +
" Get: fun" +
"ction (index) {\r\n" +
" Window" +
".this.xcall(\"SEND\"" +
", 2, index);\r\n" +
" },\r\n" +
" Close: f" +
"unction () {\r\n" +
" docu" +
"ment.body.innerHTML " +
"= \"\";\r\n" +
" Wind" +
"ow.this.state = Win" +
"dow.WINDOW_HIDDEN;\r" +
"\n" +
" },\r\n" +
" }\r\n" +
" });\r\n" +
" </script>\r\n" +
" </body>\r\n" +
"</html>";
}
}
}