I'm having a problem with DarkNet, I've written this simple LAN messenger but when I run it, it will only show the first thing i entered, just the user name, or nothing, it also crashes when i run the release build. any help would be greatly appreciated.
(heres my source btw)
#include <MikeNet.h>
#include <DarkGDK.h>
#include <cstring>
void SendPacket(_int64 packet, char* UserName, char* Text, int Red, int Blue, int Green);
void RecievePacket(_int64 packet);
void DarkGDK(void)
{
dbSetDisplayMode(600,250,32);
int Start = mnStart(3,0);
if(Start==0)
{
mnSetLocal(1, NULL, 23009, NULL, 23010);
mnStartBroadcast(1, 23010, true, true);
_int64 packet = mnCreatePacket();
char* Text;
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
while(LoopGDK())
{
Text = dbInput();
if(dbReturnKey())
SendPacket(packet, "James", Text, 150, 160, 250);
delete[] Text;
RecievePacket(packet);
if(dbEscapeKey())
break;
}
}
mnFinish(-1);
return;
}
void SendPacket(_int64 packet, char* UserName, char* Text, int Red, int Blue, int Green)
{
mnAddInt(packet, Red);
mnAddInt(packet, Blue);
mnAddInt(packet, Green);
mnAddStringC(packet, UserName, 0, true);
mnAddStringC(packet, Text, 0, true);
mnSendUDP(1, packet, NULL, false, true);
}
void RecievePacket(_int64 packet)
{
int RecieveNew=mnRecvUDP(1, packet, NULL, NULL);
if(RecieveNew==1)
{
int Red, Blue, Green;
char* str;
//Sets Text Colour
Red = mnGetUnsignedInt(packet);
Blue = mnGetUnsignedInt(packet);
Green = mnGetUnsignedInt(packet);
//Set Text Colour
dbInk(dbRGB(Red,Green,Blue), dbRGB(0,0,0));
//Display User Name
strcpy(str, "<");
strcat(str, mnGetStringC(packet, 0, true));
strcat(str,"> ");
//Display Text
strcat (str, mnGetStringC(packet, 0, true));
dbPrint(str);
delete[] str;
//Reset Text Colour
dbInk(dbRGB(255,255,255), dbRGB(0,0,0));
}
}
this is probably down to my poor coding and lack of experience with networking and DarkNet/DarkGDK, but I would very much like to fix it so I can continue my hopes of programming =) (especially game programming =D)