From 1427b28d000eef29b3fbc6fffc1388ea62688999 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Sat, 19 Feb 2022 18:59:00 -0600 Subject: [PATCH] All packet buffers are now uint8_t instead of char. Few memory leaks and NULL issues fixed. --- client/assets/chat.svg | 358 +++++++++++++++++++ client/assets/door.png | 3 - client/assets/dos.png | 3 - client/assets/email.svg | 140 ++++++++ client/assets/forums.svg | 15 + client/assets/games.svg | 223 ++++++++++++ client/assets/if.png | 3 - client/assets/logo.xcf | 4 +- client/assets/logoff.svg | 494 +++++++++++++++++++++++++++ client/assets/menu.xcf | 3 - client/assets/profile.svg | 25 ++ client/in/{ => gui}/mbie32.png | 0 client/in/{ => gui}/mbii32.png | 0 client/in/{ => gui}/mbim32.png | 0 client/in/{ => gui}/mbiq32.png | 0 client/in/{ => gui}/mbiw32.png | 0 client/in/{ => gui}/mouse.png | 0 client/in/logo.png | 3 - client/in/menu/48chat.png | 3 + client/in/menu/48email.png | 3 + client/in/menu/48forums.png | 3 + client/in/menu/48games.png | 3 + client/in/menu/48logoff.png | 3 + client/in/menu/48profile.png | 3 + client/in/{ => welcome}/dconnect.png | 0 client/in/{ => welcome}/ddialing.png | 0 client/in/{ => welcome}/dinit.png | 0 client/in/welcome/logo.png | 3 + client/src/config.c | 4 +- client/src/dos/vesa.c | 2 +- client/src/file.c | 6 +- client/src/gui/font.c | 7 +- client/src/gui/gui.c | 9 +- client/src/gui/msgbox.c | 10 +- client/src/login.c | 2 +- client/src/main.c | 25 +- client/src/menu.c | 163 ++++----- client/src/signup.c | 2 +- client/src/system/cache.c | 3 - client/src/system/comport.c | 68 +--- client/src/system/comport.h | 12 +- client/src/system/network.c | 12 +- client/src/welcome.c | 12 +- font/font.pro | 4 +- font/src/main.c | 55 --- kpmpgsmkii.pro | 4 +- precache/precache.pro | 1 + precache/src/main.c | 32 +- server/src/client.c | 10 +- server/src/client.h | 2 +- server/src/client/file.c | 12 +- server/src/client/login.c | 2 +- server/src/client/signup.c | 2 +- server/src/client/version.c | 6 +- server/src/server.c | 4 +- shared/packet.c | 39 ++- shared/packet.h | 26 +- 57 files changed, 1506 insertions(+), 325 deletions(-) create mode 100644 client/assets/chat.svg delete mode 100644 client/assets/door.png delete mode 100644 client/assets/dos.png create mode 100644 client/assets/email.svg create mode 100644 client/assets/forums.svg create mode 100644 client/assets/games.svg delete mode 100644 client/assets/if.png create mode 100644 client/assets/logoff.svg delete mode 100644 client/assets/menu.xcf create mode 100644 client/assets/profile.svg rename client/in/{ => gui}/mbie32.png (100%) rename client/in/{ => gui}/mbii32.png (100%) rename client/in/{ => gui}/mbim32.png (100%) rename client/in/{ => gui}/mbiq32.png (100%) rename client/in/{ => gui}/mbiw32.png (100%) rename client/in/{ => gui}/mouse.png (100%) delete mode 100644 client/in/logo.png create mode 100644 client/in/menu/48chat.png create mode 100644 client/in/menu/48email.png create mode 100644 client/in/menu/48forums.png create mode 100644 client/in/menu/48games.png create mode 100644 client/in/menu/48logoff.png create mode 100644 client/in/menu/48profile.png rename client/in/{ => welcome}/dconnect.png (100%) rename client/in/{ => welcome}/ddialing.png (100%) rename client/in/{ => welcome}/dinit.png (100%) create mode 100644 client/in/welcome/logo.png diff --git a/client/assets/chat.svg b/client/assets/chat.svg new file mode 100644 index 0000000..8f3054a --- /dev/null +++ b/client/assets/chat.svg @@ -0,0 +1,358 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + tango inetrnet group chat + 2010-03-29T08:03:30 + "Group chat" icon from <a href="http://tango.freedesktop.org/Tango_Desktop_Project"> Tango Project </a> \n<br><br> \nSince version 0.8.90 Tango Project icons are Public Domain: <a href="http://tango.freedesktop.org/Frequently_Asked_Questions#Terms_of_Use.3F"> Tango Project FAQ </a> + https://openclipart.org/detail/35209/tango-inetrnet-group-chat-by-warszawianka + + + warszawianka + + + + + balloon + externalsource + icon + speech + tango + + + + + + + + + + + diff --git a/client/assets/door.png b/client/assets/door.png deleted file mode 100644 index d55c4c8..0000000 --- a/client/assets/door.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:fac67f341ffec347d5722fbf9cae810d13666d308d01722f11397e9cd2d65dbf -size 3250 diff --git a/client/assets/dos.png b/client/assets/dos.png deleted file mode 100644 index 62fefd7..0000000 --- a/client/assets/dos.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d009a129322e0ef2c6088f6ccc6249e53c814dea47df7c8f25bc11569cf56ac6 -size 5145 diff --git a/client/assets/email.svg b/client/assets/email.svg new file mode 100644 index 0000000..caba709 --- /dev/null +++ b/client/assets/email.svg @@ -0,0 +1,140 @@ + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + ftmail generic + 2011-01-31T02:06:24 + Originally uploaded by Danny Allen for OCAL 0.18 this icon is part of the flat theme + https://openclipart.org/detail/113293/ftmail-generic-by-anonymous + + + Anonymous + + + + + flat + icon + theme + + + + + + + + + + + diff --git a/client/assets/forums.svg b/client/assets/forums.svg new file mode 100644 index 0000000..c83b907 --- /dev/null +++ b/client/assets/forums.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + image/svg+xmlOpenclipartBlank sticky note 12006-12-26T00:00:00https://openclipart.org/detail/17621/-by--17621lemmling + \ No newline at end of file diff --git a/client/assets/games.svg b/client/assets/games.svg new file mode 100644 index 0000000..3d48eb4 --- /dev/null +++ b/client/assets/games.svg @@ -0,0 +1,223 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + ftpackage games + 2011-01-31T02:14:23 + Originally uploaded by Danny Allen for OCAL 0.18 this icon is part of the flat theme + https://openclipart.org/detail/116275/ftpackage-games-by-anonymous + + + Anonymous + + + + + flat + icon + theme + + + + + + + + + + + diff --git a/client/assets/if.png b/client/assets/if.png deleted file mode 100644 index 121647d..0000000 --- a/client/assets/if.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:79e08a0328c8e1d71b24028dacea5d1726c6ad73983b0638e6ec6724d3b4232d -size 3047 diff --git a/client/assets/logo.xcf b/client/assets/logo.xcf index a2a3a8e..b5662c9 100644 --- a/client/assets/logo.xcf +++ b/client/assets/logo.xcf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:292b9e00f729c5b7f27799d8c19ba0af4f50480189036174728a7031285327f9 -size 36941 +oid sha256:5b3d55e7ac6b10d82bf421887b4c281bc4c27e18da945f38c03b6ebeaf829604 +size 36981 diff --git a/client/assets/logoff.svg b/client/assets/logoff.svg new file mode 100644 index 0000000..897a575 --- /dev/null +++ b/client/assets/logoff.svg @@ -0,0 +1,494 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + tango system log out + 2010-03-26T15:33:56 + "Log out" icon from <a href="http://tango.freedesktop.org/Tango_Desktop_Project"> Tango Project </a> \n<br><br> \nSince version 0.8.90 Tango Project icons are Public Domain: <a href="http://tango.freedesktop.org/Frequently_Asked_Questions#Terms_of_Use.3F"> Tango Project FAQ </a> + https://openclipart.org/detail/34279/tango-system-log-out-by-warszawianka + + + warszawianka + + + + + arrow + door + exit + externalsource + icon + logout + open + quit + red + tango + + + + + + + + + + + diff --git a/client/assets/menu.xcf b/client/assets/menu.xcf deleted file mode 100644 index 88d575d..0000000 --- a/client/assets/menu.xcf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:58e69ccb53b34298d69737cb3160f5bb7fafaa87747c1474b3331a6a8e1fe862 -size 25417 diff --git a/client/assets/profile.svg b/client/assets/profile.svg new file mode 100644 index 0000000..6411f32 --- /dev/null +++ b/client/assets/profile.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/in/mbie32.png b/client/in/gui/mbie32.png similarity index 100% rename from client/in/mbie32.png rename to client/in/gui/mbie32.png diff --git a/client/in/mbii32.png b/client/in/gui/mbii32.png similarity index 100% rename from client/in/mbii32.png rename to client/in/gui/mbii32.png diff --git a/client/in/mbim32.png b/client/in/gui/mbim32.png similarity index 100% rename from client/in/mbim32.png rename to client/in/gui/mbim32.png diff --git a/client/in/mbiq32.png b/client/in/gui/mbiq32.png similarity index 100% rename from client/in/mbiq32.png rename to client/in/gui/mbiq32.png diff --git a/client/in/mbiw32.png b/client/in/gui/mbiw32.png similarity index 100% rename from client/in/mbiw32.png rename to client/in/gui/mbiw32.png diff --git a/client/in/mouse.png b/client/in/gui/mouse.png similarity index 100% rename from client/in/mouse.png rename to client/in/gui/mouse.png diff --git a/client/in/logo.png b/client/in/logo.png deleted file mode 100644 index a628edc..0000000 --- a/client/in/logo.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:fd5d1cf047982cfe2523e5636d8a5db75cde08769c76b7da576c5e8fe63abcf1 -size 46867 diff --git a/client/in/menu/48chat.png b/client/in/menu/48chat.png new file mode 100644 index 0000000..6e0242b --- /dev/null +++ b/client/in/menu/48chat.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6a2f6acf75e0631af38289c08160ca9636feacba1aeb22641ef856ba9a04bbc +size 1406 diff --git a/client/in/menu/48email.png b/client/in/menu/48email.png new file mode 100644 index 0000000..07cd8f2 --- /dev/null +++ b/client/in/menu/48email.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2798270594eaf78ec8a88287ca9533063493d7f172aec0b384a32f6e8715b55e +size 1297 diff --git a/client/in/menu/48forums.png b/client/in/menu/48forums.png new file mode 100644 index 0000000..c5f4734 --- /dev/null +++ b/client/in/menu/48forums.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e2c3f6fa52d7c3fc22afb0676c0a2d5dbf1d69556a81054729ee45d61ec641f +size 1302 diff --git a/client/in/menu/48games.png b/client/in/menu/48games.png new file mode 100644 index 0000000..8e4b81e --- /dev/null +++ b/client/in/menu/48games.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2dd87a9eb7b05b38af0396a832b5cafc51ea36d35237638db3253037562262c4 +size 3318 diff --git a/client/in/menu/48logoff.png b/client/in/menu/48logoff.png new file mode 100644 index 0000000..bf2d284 --- /dev/null +++ b/client/in/menu/48logoff.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f320e805a6af7363511ee70afea8cead673b72241a86decfb48004f58ff0f995 +size 1615 diff --git a/client/in/menu/48profile.png b/client/in/menu/48profile.png new file mode 100644 index 0000000..053f138 --- /dev/null +++ b/client/in/menu/48profile.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a75347b93d373a95a2e8b4a4c2a25a9256a5de5c2c442eb3ff162c832e753d23 +size 2308 diff --git a/client/in/dconnect.png b/client/in/welcome/dconnect.png similarity index 100% rename from client/in/dconnect.png rename to client/in/welcome/dconnect.png diff --git a/client/in/ddialing.png b/client/in/welcome/ddialing.png similarity index 100% rename from client/in/ddialing.png rename to client/in/welcome/ddialing.png diff --git a/client/in/dinit.png b/client/in/welcome/dinit.png similarity index 100% rename from client/in/dinit.png rename to client/in/welcome/dinit.png diff --git a/client/in/welcome/logo.png b/client/in/welcome/logo.png new file mode 100644 index 0000000..5f72907 --- /dev/null +++ b/client/in/welcome/logo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af20f782b1c70caac2e7126857c443c3db9e12a88415c4b8b21c11a782055d6b +size 42970 diff --git a/client/src/config.c b/client/src/config.c index 7517320..a4c20ec 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -72,8 +72,8 @@ void configStartup(char *file) { _configName = utilAppNameWithNewExtensionGet(file, "ini"); // Numeric Defaults. - __configData.videoWidth = 800; - __configData.videoHeight = 600; + __configData.videoWidth = 640; + __configData.videoHeight = 480; __configData.videoDepth = 16; __configData.serialCom = 0; __configData.serverPort = 16550; diff --git a/client/src/dos/vesa.c b/client/src/dos/vesa.c index 038a71f..91e7ded 100644 --- a/client/src/dos/vesa.c +++ b/client/src/dos/vesa.c @@ -359,7 +359,7 @@ static uint8_t vbeIsDesiredMode(void) { // Packed or Direct Color mode. if (_vbeModeInfo.memoryModel == VBE_MM_PACKED || _vbeModeInfo.memoryModel == VBE_MM_DCOLOR) { // Resolution minimum of 640x480. - if (_vbeModeInfo.xResolution >= 800 && _vbeModeInfo.yResolution >= 600) { + if (_vbeModeInfo.xResolution >= 640 && _vbeModeInfo.yResolution >= 480) { // Multiple of 8 if (DIVISIBLE_BY_EIGHT(_vbeModeInfo.xResolution) && DIVISIBLE_BY_EIGHT(_vbeModeInfo.yResolution)) { // Valid mode! diff --git a/client/src/file.c b/client/src/file.c index ccb18ec..79e1253 100644 --- a/client/src/file.c +++ b/client/src/file.c @@ -94,7 +94,7 @@ void fileCacheCheck(fileCallback callback, char *vpaths[]) { static void fileCheckNext(void) { PacketEncodeDataT encoded = { 0 }; - char *packetData = NULL; + uint8_t *packetData = NULL; uint16_t length = 0; uint32_t temp = 0; uint8_t doRecheck = 0; @@ -169,7 +169,7 @@ static void fileShowDialog(void) { T_TITLE, P("Downloading..."), T_LABEL, T_DONE, T_TIMER, O(_timTimer), - T_EVENT, P(timTimerTimeout), + T_EVENT, P(timTimerTimeout), // ***TODO*** This should probably be placed on the desktop so it can run while the first file is checked. T_VALUE, 4 * 5, T_ENABLED, 1, T_TIMER, T_DONE, @@ -195,7 +195,7 @@ static void fileShowError(char *message) { static void packetHandler(PacketDecodeDataT *packet) { FileResponseT response = 0; PacketEncodeDataT encoded = { 0 }; - char *packetData = NULL; + uint8_t *packetData = NULL; uint16_t length = 0; uint32_t temp = 0; diff --git a/client/src/gui/font.c b/client/src/gui/font.c index e2bdb42..6be67e3 100644 --- a/client/src/gui/font.c +++ b/client/src/gui/font.c @@ -118,6 +118,7 @@ void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, offset = cy * (font->span / 2) * font->height + cx * ((float)font->width / 8.0f); for (yl=0; ylheight; yl++) { + // We do 4 pixels unrolled hoping it's fast. data = font->bits[offset]; offset += (font->span / 2); @@ -132,6 +133,8 @@ void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, surfacePutPixel(x + 2, yp, data & 0x20 ? foreground : background); surfacePutPixel(x + 3, yp, data & 0x10 ? foreground : background); } + + yp++; } } else { // Full Byte. @@ -145,7 +148,7 @@ void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, // We do 8 pixels unrolled hoping it's fast. data = font->bits[offset]; offset += font->span; -#ifndef FONT_DEBUGGING + surfacePutPixel(x, yp, data & 0x80 ? foreground : background); surfacePutPixel(x + 1, yp, data & 0x40 ? foreground : background); surfacePutPixel(x + 2, yp, data & 0x20 ? foreground : background); @@ -154,7 +157,7 @@ void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, surfacePutPixel(x + 5, yp, data & 0x04 ? foreground : background); surfacePutPixel(x + 6, yp, data & 0x02 ? foreground : background); surfacePutPixel(x + 7, yp, data & 0x01 ? foreground : background); -#endif + yp++; } } diff --git a/client/src/gui/gui.c b/client/src/gui/gui.c index 9fffc58..da7cf55 100644 --- a/client/src/gui/gui.c +++ b/client/src/gui/gui.c @@ -472,11 +472,14 @@ void guiMouseProcess(MouseT *mouse) { void guiPaint(WidgetT *widget) { + PendingEventsT *event = NULL; + // Process any pending events. while (arrlen(_guiPendingEvents)) { - _guiPendingEvents[0]->callback(_guiPendingEvents[0]->widget); - DEL(_guiPendingEvents[0]); + event = _guiPendingEvents[0]; arrdel(_guiPendingEvents, 0); + _guiPendingEvents[0]->callback(event->widget); + DEL(event); } arrfree(_guiPendingEvents); @@ -662,7 +665,7 @@ DesktopT *guiStartup(void) { _guiColor[COLOR_LISTBOX_ARROWS_INACTIVE] = vbeColorMake( 80, 84, 80); // Load font. ***TODO*** This should probably be provided by an API call to remove it from in here. - _guiFont = fontLoad(cacheFilenameGet("system:vga8x14")); + _guiFont = fontLoad(cacheFilenameGet("gui:vga8x14.dat")); // Create desktop and return it. Remember it for later. _guiDesktop = desktopNew(); diff --git a/client/src/gui/msgbox.c b/client/src/gui/msgbox.c index 86f4829..f1f9d8f 100644 --- a/client/src/gui/msgbox.c +++ b/client/src/gui/msgbox.c @@ -57,11 +57,11 @@ static ButtonT *_btnThree = NULL; //***TODO*** This depends on the cache system which isn't really part of the GUI. static char *_iconFiles[MSGBOX_ICON_COUNT] = { - "system:exclamation", - "system:warning", - "system:information", - "system:message", - "system:question" + "gui:exclamation.png", + "gui:warning.png", + "gui:information.png", + "gui:message.png", + "gui:question.png" }; diff --git a/client/src/login.c b/client/src/login.c index 0ba81f8..3685102 100644 --- a/client/src/login.c +++ b/client/src/login.c @@ -206,7 +206,7 @@ static void setButtons(uint8_t enabled) { static void timLoginProgress(WidgetT *widget) { - char *packetData; + uint8_t *packetData; uint16_t length; PacketEncodeDataT encoded; TimerT *t = (TimerT *)widget; diff --git a/client/src/main.c b/client/src/main.c index 9469c2f..3494ba8 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -193,7 +193,7 @@ static uint8_t startup(int argc, char *argv[]) { guiStartup(); netStartup(); - _pointer = imageLoad(cacheFilenameGet("system:mouse")); + _pointer = imageLoad(cacheFilenameGet("gui:mouse.png")); _alpha = imagePixelGet(_pointer, 5, 0); tableLoad(); @@ -300,12 +300,33 @@ int main(int argc, char *argv[]) { if (hasValidSettings()) { // We have what we need, start the client. welcomeShow(); + eventLoop(); } else { // Run the setup. settingsShow(checkSettings); } - eventLoop(); + /* + uint8_t length = 79; + uint8_t packet[] = { + 0x00, 0x0b, 0x01, 0x03, 0x00, 0x00, 0x00, 0xf6, 0x0c, 0x00, 0x00, 0x32, 0x64, + 0x64, 0x38, 0x37, 0x61, 0x39, 0x65, 0x62, 0x37, 0x62, 0x30, 0x35, 0x62, 0x33, + 0x38, 0x61, 0x66, 0x30, 0x33, 0x39, 0x36, 0x61, 0x38, 0x33, 0x32, 0x62, 0x35, + 0x63, 0x61, 0x66, 0x63, 0x35, 0x31, 0x65, 0x61, 0x33, 0x36, 0x64, 0x33, 0x35, + 0x32, 0x33, 0x37, 0x36, 0x33, 0x38, 0x64, 0x62, 0x33, 0x32, 0x35, 0x33, 0x30, + 0x33, 0x37, 0x35, 0x36, 0x32, 0x32, 0x36, 0x32, 0x63, 0x34, 0x00, 0x44, 0x7e, + 0x00 + }; + PacketDecodeDataT decoded; + + if (packetDecode(__packetThreadData, &decoded, (char *)packet, length)) { + logWrite("Packet decoded: %d\n", decoded.packetType); + } else { + logWrite("Packet NOT decoded.\n"); + } + + shutdown(); + */ return 0; } diff --git a/client/src/menu.c b/client/src/menu.c index 675fb3f..58a23a0 100644 --- a/client/src/menu.c +++ b/client/src/menu.c @@ -33,119 +33,124 @@ #include "file.h" -static void btnLogoffClick(WidgetT *widget); -static void btnOptionsClick(WidgetT *widget); static void btnMsgBoxLogoff(MsgBoxButtonT button); static void menuFilesReady(void); -static void picDoorClick(WidgetT *widget); -static void setButtons(uint8_t enabled); +static void picChatClick(WidgetT *widget); +static void picEmailClick(WidgetT *widget); +static void picForumsClick(WidgetT *widget); +static void picGamesClick(WidgetT *widget); +static void picLogoffClick(WidgetT *widget); +static void picProfileClick(WidgetT *widget); -static WindowT *_winMenu = NULL; -static PictureT *_picDoor = NULL; -static PictureT *_picDOS = NULL; -static PictureT *_picIF = NULL; -static ButtonT *_btnOptions = NULL; -static ButtonT *_btnLogoff = NULL; - - -static void btnLogoffClick(WidgetT *widget) { - (void)widget; - - setButtons(0); - msgBoxTwo("Logoff?", MSGBOX_ICON_QUESTION, "This will disconnect you from the server.", "Okay", btnMsgBoxLogoff, "Cancel", btnMsgBoxLogoff); -} +static PictureT *_picChat = NULL; +static PictureT *_picEmail = NULL; +static PictureT *_picForums = NULL; +static PictureT *_picGames = NULL; +static PictureT *_picLogoff = NULL; +static PictureT *_picProfile = NULL; static void btnMsgBoxLogoff(MsgBoxButtonT button) { if (button == MSGBOX_BUTTON_ONE) { - guiDelete(D(_winMenu)); + guiDelete(D(_picProfile)); + guiDelete(D(_picLogoff)); + guiDelete(D(_picGames)); + guiDelete(D(_picForums)); + guiDelete(D(_picEmail)); + guiDelete(D(_picChat)); // ***TODO*** Need a way to close all other windows. hangupShow(welcomeShow); - } else { - setButtons(1); } } -static void btnOptionsClick(WidgetT *widget) { - (void)widget; - // ***TODO*** - msgBoxOne("Options", MSGBOX_ICON_MESSAGE, "Yeah, this doesn't do anything yet.", "Okay", NULL); -} - - static void menuFilesReady(void) { - char *dos = strdup(cacheFilenameGet("menu:dosgames.png")); - char *door = strdup(cacheFilenameGet("menu:doorgames.png")); - char *fiction = strdup(cacheFilenameGet("menu:interactivefiction.png")); + uint16_t x = vbeDisplayWidthGet() - 49; + uint16_t y = vbeDisplayHeightGet() - 49; - TagItemT uiMenu[] = { - T_START, - T_WINDOW, O(_winMenu), - T_TITLE, P("KangaWorld Main Menu"), - T_X, vbeDisplayWidthGet() - 360, T_Y, vbeDisplayHeightGet() - 285, - T_WIDTH, 350, T_HEIGHT, 275, + _picLogoff = pictureNew(x, y, cacheFilenameGet("menu:48logoff.png")); + pictureClickHandlerSet(_picLogoff, picLogoffClick); + guiAttach(guiRootGet(), W(_picLogoff)); + x -= 49; - T_PICTURE, O(_picDOS), - T_FILENAME, P(dos), - T_X, 18, T_Y, 18, - T_PICTURE, T_DONE, + _picForums = pictureNew(x, y, cacheFilenameGet("menu:48forums.png")); + pictureClickHandlerSet(_picForums, picForumsClick); + guiAttach(guiRootGet(), W(_picForums)); + x -= 49; - T_PICTURE, O(_picDoor), - T_FILENAME, P(door), - T_X, 18, T_Y, 77, - T_CLICK, P(picDoorClick), - T_PICTURE, T_DONE, + _picEmail = pictureNew(x, y, cacheFilenameGet("menu:48email.png")); + pictureClickHandlerSet(_picEmail, picEmailClick); + guiAttach(guiRootGet(), W(_picEmail)); + x -= 49; - T_PICTURE, O(_picIF), - T_FILENAME, P(fiction), - T_X, 18, T_Y, 136, - T_PICTURE, T_DONE, + _picGames = pictureNew(x, y, cacheFilenameGet("menu:48games.png")); + pictureClickHandlerSet(_picGames, picGamesClick); + guiAttach(guiRootGet(), W(_picGames)); + x -= 49; - T_BUTTON, O(_btnOptions), - T_TITLE, P("Options"), - T_X, 23, T_Y, 202, - T_CLICK, P(btnOptionsClick), - T_BUTTON, T_DONE, + _picChat = pictureNew(x, y, cacheFilenameGet("menu:48chat.png")); + pictureClickHandlerSet(_picChat, picChatClick); + guiAttach(guiRootGet(), W(_picChat)); + x -= 49; - T_BUTTON, O(_btnLogoff), - T_TITLE, P("Logoff"), - T_X, 245, T_Y, 202, - T_CLICK, P(btnLogoffClick), - T_BUTTON, T_DONE, - - T_WINDOW, T_DONE, - T_END - }; - - tagListRun(uiMenu); - - DEL(fiction); - DEL(door); - DEL(dos); + _picProfile = pictureNew(x, y, cacheFilenameGet("menu:48profile.png")); + pictureClickHandlerSet(_picProfile, picProfileClick); + guiAttach(guiRootGet(), W(_picProfile)); } void menuShow(void) { char *fileList[] = { - "menu:dosgames.png", - "menu:doorgames.png", - "menu:interactivefiction.png", + "menu:48chat.png", + "menu:48email.png", + "menu:48forums.png", + "menu:48games.png", + "menu:48logoff.png", + "menu:48profile.png", NULL }; fileCacheCheck(menuFilesReady, fileList); } -static void picDoorClick(WidgetT *widget) { - +static void picChatClick(WidgetT *widget) { + (void)widget; + // ***TODO*** + msgBoxOne("Chat", MSGBOX_ICON_MESSAGE, "Yeah, this doesn't do anything yet.", "Okay", NULL); } -static void setButtons(uint8_t enabled) { - // ***TODO*** This should disable the entire dialog instead of just the buttons. Need to finish the Enable GUI code first. - widgetEnableSet(W(_btnOptions), enabled); - widgetEnableSet(W(_btnLogoff), enabled); +static void picEmailClick(WidgetT *widget) { + (void)widget; + // ***TODO*** + msgBoxOne("E-Mail", MSGBOX_ICON_MESSAGE, "Yeah, this doesn't do anything yet.", "Okay", NULL); +} + + +static void picForumsClick(WidgetT *widget) { + (void)widget; + // ***TODO*** + msgBoxOne("Forums", MSGBOX_ICON_MESSAGE, "Yeah, this doesn't do anything yet.", "Okay", NULL); +} + + +static void picGamesClick(WidgetT *widget) { + (void)widget; + // ***TODO*** + msgBoxOne("Games", MSGBOX_ICON_MESSAGE, "Yeah, this doesn't do anything yet.", "Okay", NULL); +} + + +static void picLogoffClick(WidgetT *widget) { + (void)widget; + msgBoxTwo("Logoff?", MSGBOX_ICON_QUESTION, "This will disconnect you from the server.", "Okay", btnMsgBoxLogoff, "Cancel", btnMsgBoxLogoff); +} + + +static void picProfileClick(WidgetT *widget) { + (void)widget; + // ***TODO*** + msgBoxOne("Options", MSGBOX_ICON_MESSAGE, "Yeah, this doesn't do anything yet.", "Okay", NULL); } diff --git a/client/src/signup.c b/client/src/signup.c index 31f5199..d8a2587 100644 --- a/client/src/signup.c +++ b/client/src/signup.c @@ -262,7 +262,7 @@ void signupShow(void) { static void timSignUpProgress(WidgetT *widget) { PacketEncodeDataT encoded; uint16_t length; - char *packetData; + uint8_t *packetData; TimerT *t = (TimerT *)widget; switch (_state) { diff --git a/client/src/system/cache.c b/client/src/system/cache.c index 600ee2f..d2e4164 100644 --- a/client/src/system/cache.c +++ b/client/src/system/cache.c @@ -18,9 +18,6 @@ */ -// ***TODO*** Maybe add a cacheFOpen() and cacheFClose() for reading and writing directly to virtual pathnames? - - #include "thirdparty/SHA256/sha256.h" #include "cache.h" diff --git a/client/src/system/comport.c b/client/src/system/comport.c index 1482330..dd7a76d 100644 --- a/client/src/system/comport.c +++ b/client/src/system/comport.c @@ -22,10 +22,10 @@ #include "config.h" -void comPacketSender(char *data, uint32_t length, void *userData) { +void comPacketSender(uint8_t *data, uint32_t length, void *userData) { (void)userData; - comWrite(__configData.serialCom - 1, data, length); + comWrite(__configData.serialCom - 1, (char *)data, length); } @@ -39,67 +39,3 @@ int comReceiveBufferFlush(int com) { return result; } - - -/* -TASKBEGIN(comWaitWithTimeout) - int32_t r; - uint32_t quarterTicks; - int32_t count; - int32_t bufferIndex; - char incoming[2]; - ComWaitWithTimeoutT *args; - - taskCode({ - // Returns number of bytes read into buffer. - // Value is positive if "expect" was found. - // Value is negative if not found. - - logWrite("Entering comWaitWithTimeout\n"); - - self->args = (ComWaitWithTimeoutT *)data; - - while (self->quarterTicks <= self->args->quarterSeconds) { - - // logWrite("Calling comRead\n"); - self->r = comRead(self->args->com, self->incoming, 1); - // logWrite("Back from comRead with %d\n", self->r); - - if (self->r == 1) { - self->args->buffer[self->bufferIndex++] = self->incoming[0]; - self->args->buffer[self->bufferIndex] = 0; - if (self->incoming[0] == self->args->expecting[self->count]) { - self->count++; - if (self->count == (int)strlen(self->args->expecting)) { - // Found our expect. - break; - } - } else { - self->count = 0; - } - if (self->bufferIndex == self->args->len - 1) { - // Out of buffer. - break; - } - } - - // logWrite("Yielding from comWaitWithTimeout\n"); - taskYield(); - // logWrite("Back in comWaitWithTimeout\n"); - - if (__timerQuarterSecondTick) { - self->quarterTicks++; - logWrite("Tick\n"); - } - } - - logWrite("Exiting comWaitWithTimeout\n"); - - if (self->count == (int)strlen(self->args->expecting)) { - self->args->result = self->bufferIndex; - } - - self->args->result = -self->bufferIndex; - }); -TASKEND -*/ diff --git a/client/src/system/comport.h b/client/src/system/comport.h index 3441be6..a5b4440 100644 --- a/client/src/system/comport.h +++ b/client/src/system/comport.h @@ -26,16 +26,6 @@ #include "packet.h" -typedef struct ComWaitWithTimeoutS { - int32_t result; - uint8_t com; - char *buffer; - int32_t len; - uint32_t quarterSeconds; - char *expecting; -} ComWaitWithTimeoutT; - - #ifdef __linux__ #define SER_SUCCESS 0 @@ -62,7 +52,7 @@ int comWrite(int com, const char *data, int len); #endif -void comPacketSender(char *data, uint32_t length, void *userData); +void comPacketSender(uint8_t *data, uint32_t length, void *userData); int comReceiveBufferFlush(int com); diff --git a/client/src/system/network.c b/client/src/system/network.c index 8cde556..3685fb1 100644 --- a/client/src/system/network.c +++ b/client/src/system/network.c @@ -104,19 +104,21 @@ void netPacketHandlerStop(void) { void netProcess(void) { int32_t r; - char buffer[1024]; + uint8_t buffer[1024]; PacketDecodeDataT *packet; PacketDecodeDataT decoded; PacketEncodeDataT encoded; - // ***TODO*** Detect disconnection. Maybe have callbacks registered that can notify tasks? + // ***TODO*** Detect disconnection. Maybe have callbacks registered that can notify open windows? if (_netRunning) { // Read pending bytes. - r = comRead(__configData.serialCom - 1, buffer, 1024); + r = comRead(__configData.serialCom - 1, (char *)buffer, 1024); // New data or not, process anything in the queue. if (packetDecode(__packetThreadData, &decoded, buffer, r)) { + //logWrite("Packet In: %d\n", decoded.packetType); + //packetDebugPrint((uint8_t *)decoded.data, decoded.length); switch (decoded.packetType) { case PACKET_TYPE_PING: // Reply with PONG @@ -139,7 +141,7 @@ void netProcess(void) { packet->channel = decoded.channel; packet->length = decoded.length; packet->packetType = decoded.packetType; - packet->data = (char *)malloc(decoded.length); + packet->data = (uint8_t *)malloc(decoded.length); memcpy(packet->data, decoded.data, decoded.length); // Send it to the subscriber. _systemHandlers[r](packet); @@ -153,7 +155,7 @@ void netProcess(void) { packet->channel = decoded.channel; packet->length = decoded.length; packet->packetType = decoded.packetType; - packet->data = (char *)malloc(decoded.length); + packet->data = (uint8_t *)malloc(decoded.length); memcpy(packet->data, decoded.data, decoded.length); // Send it to the subscriber. _channels[r].value(packet); diff --git a/client/src/welcome.c b/client/src/welcome.c index b7ecb09..86694b9 100644 --- a/client/src/welcome.c +++ b/client/src/welcome.c @@ -149,7 +149,7 @@ static void packetHandler(PacketDecodeDataT *packet) { shdel(__runtimeData.strings, packet->data); } // Store in string table. - shput(__runtimeData.strings, packet->data, strdup(&packet->data[strlen(packet->data) + 1])); + shput(__runtimeData.strings, packet->data, strdup((char *)&packet->data[strlen((char *)packet->data) + 1])); break; case PACKET_TYPE_VERSION: @@ -195,10 +195,10 @@ static void settingsFinished(WidgetT *widget) { void welcomeShow(void) { - char *logo = strdup(cacheFilenameGet("system:logo")); - char *init = strdup(cacheFilenameGet("system:init")); - char *dial = strdup(cacheFilenameGet("system:dialing")); - char *conn = strdup(cacheFilenameGet("system:connect")); + char *logo = strdup(cacheFilenameGet("welcome:logo.png")); + char *init = strdup(cacheFilenameGet("welcome:init.png")); + char *dial = strdup(cacheFilenameGet("welcome:dialing.png")); + char *conn = strdup(cacheFilenameGet("welcome:connect.png")); // 450x128 logo @@ -300,7 +300,7 @@ static void timWelcomeProgress(WidgetT *widget) { case S_INIT_MODEM: // Just read anything to clear the buffer. - len = comRead(__configData.serialCom - 1, buffer, 1023); + comRead(__configData.serialCom - 1, buffer, 1023); // Send actual init snprintf(buffer, 1023, "%s%c", "AT+SOCK1", 13); comWrite(__configData.serialCom - 1, buffer, strlen(buffer)); diff --git a/font/font.pro b/font/font.pro index 4b2fcf3..6921f3b 100644 --- a/font/font.pro +++ b/font/font.pro @@ -38,10 +38,8 @@ INCLUDEPATH += \ HEADERS = \ $$SHARED/stddclmr.h \ $$SHARED/thirdparty/memwatch/memwatch.h \ - $$SHARED/thirdparty/stb_image.h \ - $$GUI/font.h + $$SHARED/thirdparty/stb_image.h SOURCES = \ $$SHARED/thirdparty/memwatch/memwatch.c \ - $$GUI/font.c \ src/main.c diff --git a/font/src/main.c b/font/src/main.c index 9212673..6af8741 100644 --- a/font/src/main.c +++ b/font/src/main.c @@ -27,54 +27,10 @@ #define STBI_ONLY_PNG #include "stb_image.h" -#include "font.h" #include "stddclmr.h" -void drawChar(FontT *font, char c); void makeFont(char *source, char *target, int pixelsW, int pixelsH, int charsW, int charCount); -void test(char *fontfile); - - -void drawChar(FontT *font, char c) { - uint8_t cx; - uint8_t cy; - uint16_t offset; - uint8_t yl; - uint8_t data; - uint8_t odd; - uint16_t t; - - // Find character position in font grid. - cx = c % font->span; - cy = c / font->span; - - // Which half of the byte do we want? - odd = ((cx & 1) == 1); - - // Find offset byte based on font bits. - offset = cy * (font->span / 2) * font->height; - t = cx * ((float)font->width / 8.0f); - offset += t; - - for (yl=0; ylheight; yl++) { - data = font->bits[offset]; - offset += (font->span / 2); - - if (odd) { - printf("%c", data & 0x08 ? '#' : ' '); - printf("%c", data & 0x04 ? '#' : ' '); - printf("%c", data & 0x02 ? '#' : ' '); - printf("%c", data & 0x01 ? '#' : ' '); - } else { - printf("%c", data & 0x80 ? '#' : ' '); - printf("%c", data & 0x40 ? '#' : ' '); - printf("%c", data & 0x20 ? '#' : ' '); - printf("%c", data & 0x10 ? '#' : ' '); - } - printf("\n"); - } -} void makeFont(char *source, char *target, int pixelsW, int pixelsH, int charsW, int charCount) { @@ -125,15 +81,6 @@ void makeFont(char *source, char *target, int pixelsW, int pixelsH, int charsW, } -void test(char *fontfile) { - FontT *font = fontLoad(fontfile); - printf("Solid Smile\n"); drawChar(font, 0x02); - printf("Question Mark\n"); drawChar(font, '?'); - printf("x\n"); drawChar(font, 'x'); - fontUnload(&font); -} - - int main(int argc, char *argv[]) { (void)argc; (void)argv; @@ -143,7 +90,5 @@ int main(int argc, char *argv[]) { makeFont("/home/scott/code/kpmpgsmkii/font/in/vga8x14.png", "/home/scott/code/kpmpgsmkii/font/out/vga8x14.dat", 8, 14, 16, 256); makeFont("/home/scott/code/kpmpgsmkii/font/in/vga8x16.png", "/home/scott/code/kpmpgsmkii/font/out/vga8x16.dat", 8, 16, 16, 256); - test("/home/scott/code/kpmpgsmkii/font/out/vga4x8.dat"); - return 0; } diff --git a/kpmpgsmkii.pro b/kpmpgsmkii.pro index f5e5a8b..21077f3 100644 --- a/kpmpgsmkii.pro +++ b/kpmpgsmkii.pro @@ -20,11 +20,11 @@ TEMPLATE = subdirs CONFIG *= ORDERED -SUBDIRS = \ +#SUBDIRS = \ # client \ # server # precache - font +# font # primes OTHER_FILES = \ diff --git a/precache/precache.pro b/precache/precache.pro index fce2fc9..f4badad 100644 --- a/precache/precache.pro +++ b/precache/precache.pro @@ -27,6 +27,7 @@ SYSTEM = $$CLIENT/system THIRDP = $$CLIENT/thirdparty INCLUDEPATH += \ + $$CLIENT \ $$SHARED \ $$SHARED/thirdparty \ $$SYSTEM \ diff --git a/precache/src/main.c b/precache/src/main.c index 9da387c..3364c29 100644 --- a/precache/src/main.c +++ b/precache/src/main.c @@ -28,21 +28,25 @@ #include "stddclmr.h" +#define CLIENT "/home/scott/code/kpmpgsmkii/client/in/" +#define FONT "/home/scott/code/kpmpgsmkii/font/out/" +#define OUT "/home/scott/code/kpmpgsmkii/precache/out/" + int main(int argc, char *argv[]) { CachePreMakeListT list[] = { - { "dconnect.png", "system:connect" }, - { "ddialing.png", "system:dialing" }, - { "dinit.png", "system:init" }, - { "logo.png", "system:logo" }, - { "mbie32.png", "system:exclamation" }, - { "mbii32.png", "system:information" }, - { "mbim32.png", "system:message" }, - { "mbiq32.png", "system:question" }, - { "mbiw32.png", "system:warning" }, - { "mouse.png", "system:mouse" }, - { "vga8x14.dat", "system:vga8x14" }, - { NULL, NULL } + { CLIENT"welcome/dconnect.png", "welcome:connect.png" }, + { CLIENT"welcome/ddialing.png", "welcome:dialing.png" }, + { CLIENT"welcome/dinit.png", "welcome:init.png" }, + { CLIENT"welcome/logo.png", "welcome:logo.png" }, + { CLIENT"gui/mbie32.png", "gui:exclamation.png" }, + { CLIENT"gui/mbii32.png", "gui:information.png" }, + { CLIENT"gui/mbim32.png", "gui:message.png" }, + { CLIENT"gui/mbiq32.png", "gui:question.png" }, + { CLIENT"gui/mbiw32.png", "gui:warning.png" }, + { CLIENT"gui/mouse.png", "gui:mouse.png" }, + { FONT"vga8x14.dat", "gui:vga8x14.dat" }, + { NULL, NULL } }; (void)argc; @@ -50,8 +54,8 @@ int main(int argc, char *argv[]) { // Also run optipng -o7 on images. - cachePrePack("client.pre", list); - cachePreUnpack("client.pre"); + cachePrePack(OUT"client.pre", list); + cachePreUnpack(OUT"client.pre"); return 0; } diff --git a/server/src/client.c b/server/src/client.c index b0b9fa4..52833c6 100644 --- a/server/src/client.c +++ b/server/src/client.c @@ -45,7 +45,7 @@ static uint8_t clientDequeuePacket(ClientThreadT *client); static uint8_t clientDequeuePacket(ClientThreadT *client) { uint16_t length = 0; - char *data = NULL; + uint8_t *data = NULL; PacketDecodeDataT decode = { 0 }; ClientRawPacketT *packet = NULL; @@ -84,7 +84,7 @@ void clientQueuePacket(ClientThreadT *client, uint8_t *data, uint32_t length) { packet = (ClientRawPacketT *)malloc(sizeof(ClientRawPacketT)); if (packet) { - packet->data = (char *)malloc(length); + packet->data = (uint8_t *)malloc(length); if (packet->data) { memcpy(packet->data, data, length); packet->length = length; @@ -125,7 +125,7 @@ void *clientThread(void *data) { time_t ticks = { 0 }; time_t lastTicks = { 0 }; int8_t pingTimeout = 0; - char *packetData = NULL; + uint8_t *packetData = NULL; uint16_t length = 0; // Process packets until we're done. @@ -174,6 +174,7 @@ void *clientThread(void *data) { // ***TODO*** Write ping stats to database. // Clean up client data on the way out. + // ***TODO*** valgrind says this isn't working. while (arrlen(client->packetQueue) > 0) { if (client->packetQueue[0]->data) DEL(client->packetQueue[0]->data); arrdel(client->packetQueue, 0); @@ -185,6 +186,9 @@ void *clientThread(void *data) { if (client->handle) fclose(client->handle); + peer = client->peer; + peer->data = NULL; + DEL(client); pthread_exit(NULL); diff --git a/server/src/client.h b/server/src/client.h index 6189bb7..df6316d 100644 --- a/server/src/client.h +++ b/server/src/client.h @@ -30,7 +30,7 @@ typedef struct ClientRawPacketS { - char *data; + uint8_t *data; uint32_t length; } ClientRawPacketT; diff --git a/server/src/client/file.c b/server/src/client/file.c index 4b2e418..5f24a13 100644 --- a/server/src/client/file.c +++ b/server/src/client/file.c @@ -31,7 +31,7 @@ static void clientApiFileRequestNext(ClientThreadT *client, PacketDecodeDataT *d void clientApiFileRequest(ClientThreadT *client, PacketDecodeDataT *data) { FileRequestsT request = 0; PacketEncodeDataT encoded = { 0 }; - char *packetData = NULL; + uint8_t *packetData = NULL; uint16_t length = 0; // Must be logged in to do file operations. @@ -73,7 +73,7 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * char *path = NULL; char *sha256 = NULL; PacketEncodeDataT encoded = { 0 }; - char *packetData = NULL; + uint8_t *packetData = NULL; uint16_t length = 0; char shaInDB[128] = { 0 }; char buffer[1024] = { 0 }; @@ -115,6 +115,8 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * client->handle = fopen(buffer2, "rb"); if (!client->handle) { logWrite("Unable to open [%s]\n", buffer2); + DEL(sha256); + DEL(path); // ***TODO*** Handle error return; } @@ -133,8 +135,12 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * encoded.encrypt = 0; packetEncode(client->packetThreadData, &encoded, packetData, length); packetSend(client->packetThreadData, &encoded); + //packetDebugPrint((uint8_t *)encoded.dataPointer, encoded.length); DEL(packetData); + DEL(sha256); + DEL(path); + // Start sending actual file data. clientApiFileRequestNext(client, data); } @@ -145,7 +151,7 @@ static void clientApiFileRequestNext(ClientThreadT *client, PacketDecodeDataT *d uint32_t temp = 0; PacketEncodeDataT encoded = { 0 }; uint16_t length = 0; - char packetData[PACKET_MAX]; + uint8_t packetData[PACKET_MAX]; // Do we have an open file? if (client->handle) { diff --git a/server/src/client/login.c b/server/src/client/login.c index ed59aa9..b6ed272 100644 --- a/server/src/client/login.c +++ b/server/src/client/login.c @@ -24,7 +24,7 @@ void clientApiLogin(ClientThreadT *client, PacketDecodeDataT *data) { - char *packetData = NULL; + uint8_t *packetData = NULL; char *user = NULL; char *pass = NULL; PacketEncodeDataT encoded = { 0 }; diff --git a/server/src/client/signup.c b/server/src/client/signup.c index 3ac7251..61b8222 100644 --- a/server/src/client/signup.c +++ b/server/src/client/signup.c @@ -34,7 +34,7 @@ void clientApiSignup(ClientThreadT *client, PacketDecodeDataT *data) { uint8_t result = 0; char *string = NULL; char *buffer = NULL; - char *packetData = NULL; + uint8_t *packetData = NULL; PacketEncodeDataT encoded = { 0 }; uint16_t length = 0; diff --git a/server/src/client/version.c b/server/src/client/version.c index 2f8b123..b4e1d1e 100644 --- a/server/src/client/version.c +++ b/server/src/client/version.c @@ -34,7 +34,7 @@ void clientApiVersionOkay(ClientThreadT *client, PacketDecodeDataT *data) { uint64_t x = 0; uint32_t y = 0; uint16_t length = 0; - char *buffer = NULL; + uint8_t *buffer = NULL; PacketEncodeDataT encoded = { 0 }; DBTableT *record = NULL; DBTableT **table = NULL; @@ -50,7 +50,7 @@ void clientApiVersionOkay(ClientThreadT *client, PacketDecodeDataT *data) { x = strlen(record->name); y = strlen(record->data); length = x + y + 2; - buffer = (char *)malloc(length); + buffer = (uint8_t *)malloc(length); if (!buffer) { consoleMessageQueue("%ld: Unable to allocate buffer for string packet!\n", client->threadIndex); break; @@ -87,7 +87,7 @@ void clientApiVersionOkay(ClientThreadT *client, PacketDecodeDataT *data) { x = strlen(record->name); y = atol(record->data); length = x + 5; - buffer = (char *)malloc(length); + buffer = (uint8_t *)malloc(length); if (!buffer) { consoleMessageQueue("%ld: Unable to allocate buffer for number packet!\n", client->threadIndex); break; diff --git a/server/src/server.c b/server/src/server.c index 7e67d7a..87f30a3 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -36,7 +36,7 @@ static uint32_t _serverClients = 0; static pthread_mutex_t _serverMutex = { 0 }; -static void serverPacketSender(char *data, uint32_t length, void *userData); +static void serverPacketSender(uint8_t *data, uint32_t length, void *userData); void serverDisconnectClient(ClientThreadT *client) { @@ -59,7 +59,7 @@ void serverDisconnectClient(ClientThreadT *client) { } -static void serverPacketSender(char *data, uint32_t length, void *userData) { +static void serverPacketSender(uint8_t *data, uint32_t length, void *userData) { ENetPeer *peer = (ENetPeer *)userData; ENetPacket *packet = NULL; diff --git a/shared/packet.c b/shared/packet.c index d1130ee..49e3b61 100644 --- a/shared/packet.c +++ b/shared/packet.c @@ -56,7 +56,7 @@ static uint8_t _encryptionReady = 0; static void *packetAesContextCreate(uint8_t *key, uint8_t *iv); -static uint8_t packetCRC(char *data, uint16_t length, uint8_t startAt); +static uint8_t packetCRC(uint8_t *data, uint16_t length, uint8_t startAt); static uint16_t packetDHCompute(uint32_t a, uint32_t m, uint32_t n); @@ -73,10 +73,10 @@ static void *packetAesContextCreate(uint8_t *key, uint8_t *iv) { } -char *packetContentPack(uint16_t *length, char *format, ...) { +uint8_t *packetContentPack(uint16_t *length, char *format, ...) { va_list args = { 0 }; static char work[PACKET_MAX] = { 0 }; - char *result = NULL; + uint8_t *result = NULL; char *buffer = NULL; int32_t value32 = 0; @@ -111,7 +111,7 @@ char *packetContentPack(uint16_t *length, char *format, ...) { // Copy working buffer to result to return. if (*length > 0) { - result = (char *)malloc(*length); + result = (uint8_t *)malloc(*length); memcpy(result, work, *length); } @@ -119,7 +119,7 @@ char *packetContentPack(uint16_t *length, char *format, ...) { } -void packetContentUnpack(char *buffer, char *format, ...) { +void packetContentUnpack(uint8_t *buffer, char *format, ...) { va_list args = { 0 }; char **string = NULL; int32_t *value32 = NULL; @@ -140,7 +140,7 @@ void packetContentUnpack(char *buffer, char *format, ...) { // Copy string including the terminating zero. string = va_arg(args, char **); if (&buffer[length] != NULL) { - *string = strdup(&buffer[length]); + *string = strdup((const char *)&buffer[length]); length += strlen(*string) + 1; } break; @@ -156,7 +156,7 @@ void packetContentUnpack(char *buffer, char *format, ...) { } -static uint8_t packetCRC(char *data, uint16_t length, uint8_t startAt) { +static uint8_t packetCRC(uint8_t *data, uint16_t length, uint8_t startAt) { uint16_t x = 0; /* @@ -191,7 +191,7 @@ void packetDebugPrint(uint8_t *data, uint16_t length) { } -uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeData, char *input, uint16_t inputLength) { +uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeData, uint8_t *input, uint16_t inputLength) { //uint8_t sequence = 0; uint16_t unpadded = 0; int32_t x = 0; @@ -304,7 +304,7 @@ uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeDat // Copy packet data to new buffer, if any. if (threadData->length - 4 > 0) { - decodeData->data = (char *)malloc(threadData->length - 4); // 4 for 3 byte header and 1 byte CRC. + decodeData->data = (uint8_t *)malloc(threadData->length - 4); // 4 for 3 byte header and 1 byte CRC. if (!decodeData) continue; memcpy(decodeData->data, &threadData->decodeBuffer[3], threadData->length - 4); // Skip header and CRC. decodeData->length = threadData->length - 4; @@ -316,6 +316,9 @@ uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeDat // Fix length to remove header and checksum. threadData->length -= 4; + logWrite("Packet In: %d Length: %d\n\r", decodeData->packetType, decodeData->length); + //packetDebugPrint((uint8_t *)decodeData->data, decodeData->length); + // Is this a DH_REQUEST? if (decodeData->packetType == PACKET_TYPE_DH_REQUEST) { memcpy(threadData->dhModulus, decodeData->data, PACKET_ENCRYPT_KEY_SIZE * sizeof(uint16_t)); @@ -332,7 +335,7 @@ uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeDat encoded.packetType = PACKET_TYPE_DH_RESPONSE; encoded.channel = 0; // Doesn't matter for DH_RESPONSE. encoded.encrypt = 0; // Must be 0 for DH_RESPONSE. - packetEncode(threadData, &encoded, (char *)threadData->dhMyPublic, PACKET_ENCRYPT_KEY_SIZE * sizeof(uint16_t)); + packetEncode(threadData, &encoded, (uint8_t *)threadData->dhMyPublic, PACKET_ENCRYPT_KEY_SIZE * sizeof(uint16_t)); packetSend(threadData, &encoded); _encryptionReady = 1; // Responding side. continue; @@ -411,13 +414,13 @@ static uint16_t packetDHCompute(uint32_t a, uint32_t m, uint32_t n) { } -uint8_t packetEncode(PacketThreadDataT *threadData, PacketEncodeDataT *data, char *input, uint16_t length) { +uint8_t packetEncode(PacketThreadDataT *threadData, PacketEncodeDataT *data, uint8_t *input, uint16_t length) { uint16_t x = 0; uint8_t crc = 0; uint8_t control = 0; uint16_t paddedSize = 0; uint16_t inputLength = 0; - char *inputBuffer = NULL; + uint8_t *inputBuffer = NULL; // Returns 1 on success, 0 on failure. @@ -437,9 +440,9 @@ uint8_t packetEncode(PacketThreadDataT *threadData, PacketEncodeDataT *data, cha control = (((uint8_t)data->control) << 6) + (data->encrypt << 5) + (data->sequence & 0x1f); // Calculate CRC over header bytes. - crc = packetCRC((char *)&control, 1, crc); - crc = packetCRC((char *)&data->packetType, 1, crc); - crc = packetCRC((char *)&data->channel, 1, crc); + crc = packetCRC(&control, 1, crc); + crc = packetCRC((uint8_t *)&data->packetType, 1, crc); + crc = packetCRC(&data->channel, 1, crc); // Add header bytes. threadData->encodeBuffer[data->length++] = control; @@ -462,7 +465,7 @@ uint8_t packetEncode(PacketThreadDataT *threadData, PacketEncodeDataT *data, cha pkcs7_padding_pad_buffer(threadData->encryptionBuffer, length, paddedSize, 16); AES_CBC_encrypt_buffer(threadData->aesContext, threadData->encryptionBuffer, paddedSize); // Encrypted, select proper buffer. - inputBuffer = (char *)threadData->encryptionBuffer; + inputBuffer = threadData->encryptionBuffer; inputLength = paddedSize; } else { // Not encrypted, select proper buffer. @@ -521,7 +524,7 @@ void packetEncryptionSetup(PacketThreadDataT *threadData) { encoded.packetType = PACKET_TYPE_DH_REQUEST; encoded.channel = 0; // Doesn't matter for DH_REQUEST. encoded.encrypt = 0; // Must be 0 for DH_REQUEST. - packetEncode(threadData, &encoded, (char *)dhData, PACKET_ENCRYPT_KEY_SIZE * 3 * sizeof(uint16_t)); + packetEncode(threadData, &encoded, (uint8_t *)dhData, PACKET_ENCRYPT_KEY_SIZE * 3 * sizeof(uint16_t)); packetSend(threadData, &encoded); } @@ -530,6 +533,8 @@ void packetSend(PacketThreadDataT *threadData, PacketEncodeDataT *data) { // Valid control type? if (data->control != PACKET_CONTROL_BAD && data->control <= PACKET_CONTROL_COUNT) { _packetSender(data->dataPointer, data->length, threadData->senderData); + logWrite("Packet Out: %d Length: %d\n\r", data->packetType, data->length); + //packetDebugPrint((uint8_t *)data->dataPointer, data->length); } else { logWrite("Invalid PACKET_CONTROL!\n\r"); } diff --git a/shared/packet.h b/shared/packet.h index 1f32ddf..568d994 100644 --- a/shared/packet.h +++ b/shared/packet.h @@ -40,10 +40,10 @@ */ -#define PACKET_MAX 1024 // Maximum number of bytes per packet. +#define PACKET_MAX 4096 // Maximum number of bytes per packet. #define PACKET_SEQUENCE_MAX 32 // Five bits of data, 32 max. Represents size of replay history. Also maximum number of packets on the wire at a time. -#define PACKET_INPUT_QUEUE_SIZE 4096 +#define PACKET_INPUT_QUEUE_SIZE 8192 #define PACKET_BUFFER_SIZE (PACKET_MAX * 2 + 2 + 8) // Worst case, every byte is a PACKET_FRAME. Add two for ending frame. Add 8 for worst case header and CRC. #define PACKET_FRAME 0x7e @@ -64,7 +64,7 @@ typedef enum PacketControlE { typedef struct PacketDecodeDataS { // Output PacketTypeT packetType; // One of PACKET_TYPE_* - char *data; // Buffer received. MUST FREE. + uint8_t *data; // Buffer received. MUST FREE. uint16_t length; // Length of buffer. uint8_t channel; // Which data channel it arrived on. } PacketDecodeDataT; @@ -78,12 +78,12 @@ typedef struct PacketEncodeDataS { // Input & Output uint8_t sequence; // For NAK packets, input the sequence number we missed. Other packets returns the sequence of this packet. // Output - char *dataPointer; // Buffer ready to send. DO NOT FREE. + uint8_t *dataPointer; // Buffer ready to send. DO NOT FREE. uint16_t length; // Length of buffer. } PacketEncodeDataT; typedef struct PacketHistoryDataS { - char data[PACKET_BUFFER_SIZE]; + uint8_t data[PACKET_BUFFER_SIZE]; uint16_t length; uint8_t sequence; } PacketHistoryDataT; @@ -96,9 +96,9 @@ typedef struct PacketThreadDataS { PacketHistoryDataT history[PACKET_SEQUENCE_MAX]; uint8_t historyPosition; */ - char decodeBuffer[PACKET_MAX]; - char encodeBuffer[PACKET_BUFFER_SIZE]; - char decodeQueue[PACKET_INPUT_QUEUE_SIZE]; + uint8_t decodeBuffer[PACKET_MAX]; + uint8_t encodeBuffer[PACKET_BUFFER_SIZE]; + uint8_t decodeQueue[PACKET_INPUT_QUEUE_SIZE]; uint16_t decodeQueueHead; uint16_t decodeQueueTail; uint8_t inEscape; @@ -116,16 +116,16 @@ typedef struct PacketThreadDataS { } PacketThreadDataT; -typedef void (*packetSender)(char *data, uint32_t length, void *userData); +typedef void (*packetSender)(uint8_t *data, uint32_t length, void *userData); -char *packetContentPack(uint16_t *length, char *format, ...); -void packetContentUnpack(char *buffer, char *format, ...); +uint8_t *packetContentPack(uint16_t *length, char *format, ...); +void packetContentUnpack(uint8_t *buffer, char *format, ...); void packetDebugPrint(uint8_t *data, uint16_t length); -uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeData, char *input, uint16_t inputLength); +uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeData, uint8_t *input, uint16_t inputLength); void packetDecodeDataDestroy(PacketDecodeDataT **packet); void packetDecodeDataStaticDestroy(PacketDecodeDataT *packet); -uint8_t packetEncode(PacketThreadDataT *threadData, PacketEncodeDataT *data, char *input, uint16_t length); +uint8_t packetEncode(PacketThreadDataT *threadData, PacketEncodeDataT *data, uint8_t *input, uint16_t length); uint8_t packetEncryptionReady(void); void packetEncryptionSetup(PacketThreadDataT *threadData); void packetSend(PacketThreadDataT *threadData, PacketEncodeDataT *data);