diff --git a/Makefile b/Makefile index 541828b..c2a8881 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ CC=cc LIBS=-lm -generator: - ${CC} -o charactergenerator ${LIBS} character.c server: - ${CC} -o chargen chargen.c + ${CC} -o chargen ${LIBS} chargen.c all: server generator diff --git a/character.c b/character.c index 1766880..6eb1525 100644 --- a/character.c +++ b/character.c @@ -317,9 +317,13 @@ void genBackground(){ } } -int main(){ +char * genChar(char* output){ + profs = 0; + languages = 0; + for(int i = 0; i <= 100; i++){ + otherprofs[i] = '\0'; + } int i; - strlcat(otherprofs, "", 1); genRace(); genClass(); genBackground(); @@ -327,111 +331,113 @@ int main(){ stats[i] = dieroll(3,6); mods[i] = floor((stats[i]/2)-5); } - printf("Race = %s\nBackground = %s\nClass = %s\nStr = %d %d\nDex = %d %d\nCon = %d %d\nInt = %d %d\nWis = %d %d\nCha = %d %d\n\nHP: %d\n", race, background, class, stats[STR], mods[STR], stats[DEX], mods[DEX], stats[CON], mods[CON], stats[INT], mods[INT], stats[WIS], mods[WIS], stats[CHA], mods[CHA], hp); + snprintf(output, 512, "Race = %s\r\nBackground = %s\r\nClass = %s\r\nStr = %d %d\r\nDex = %d %d\r\nCon = %d %d\r\nInt = %d %d\r\nWis = %d %d\r\nCha = %d %d\r\n\r\nHP: %d\r\n", race, background, class, stats[STR], mods[STR], stats[DEX], mods[DEX], stats[CON], mods[CON], stats[INT], mods[INT], stats[WIS], mods[WIS], stats[CHA], mods[CHA], hp); - printf("Proficiences:\n"); + strlcat(output,"Proficiences:\r\n",512); if((ATHLETICS & profs) != 0){ - printf("Athletics\n"); + strlcat(output,"Athletics\r\n",512); } if((ACROBATICS & profs) != 0){ - printf("Acrobatics\n"); + strlcat(output,"Acrobatics\r\n",512); } if((SLEIGHTOFHAND & profs) != 0){ - printf("Sleight of Hand\n"); + strlcat(output,"Sleight of Hand\r\n",512); } if((STEALTH & profs) != 0){ - printf("Stealth\n"); + strlcat(output,"Stealth\r\n",512); } if((ARCANA & profs) != 0){ - printf("Arcana\n"); + strlcat(output,"Arcana\r\n",512); } if((HISTORY & profs) != 0){ - printf("History\n"); + strlcat(output,"History\r\n",512); } if((INVESTIGATION & profs) != 0){ - printf("Investigation\n"); + strlcat(output,"Investigation\r\n",512); } if((NATURE & profs) != 0){ - printf("Nature\n"); + strlcat(output,"Nature\r\n",512); } if((RELIGION & profs) != 0){ - printf("Regligion\n"); + strlcat(output,"Regligion\r\n",512); } if((ANIMALHANDLING & profs) != 0){ - printf("Animal Handling\n"); + strlcat(output,"Animal Handling\r\n",512); } if((INSIGHT & profs) != 0){ - printf("Insight\n"); + strlcat(output,"Insight\r\n",512); } if((MEDICINE & profs) != 0){ - printf("Medicine\n"); + strlcat(output,"Medicine\r\n",512); } if((PERCEPTION & profs) != 0){ - printf("Perception\n"); + strlcat(output,"Perception\r\n",512); } if((SURVIVAL & profs) != 0){ - printf("Survival\n"); + strlcat(output,"Survival\r\n",512); } if((DECEPTION & profs) != 0){ - printf("Deception\n"); + strlcat(output,"Deception\r\n",512); } if((INTIMIDATION & profs) != 0){ - printf("Intimidation\n"); + strlcat(output,"Intimidation\r\n",512); } if((PERFORMANCE & profs) != 0){ - printf("Performance\n"); + strlcat(output,"Performance\r\n",512); } if((PERSUASION & profs) != 0){ - printf("Persuaion\n"); + strlcat(output,"Persuaion\r\n",512); } - printf("\nLanguages:\nCommon\n"); + strlcat(output,"\r\nLanguages:\r\nCommon\r\n",512); if((ABYSSAL & languages) != 0){ - printf("Abyssal\n"); + strlcat(output,"Abyssal\r\n",512); } if((CELESTIAL & languages) != 0){ - printf("Celestial\n"); + strlcat(output,"Celestial\r\n",512); } if((DRACONIC & languages) != 0){ - printf("Draconic\n"); + strlcat(output,"Draconic\r\n",512); } if((DEEPSPEECH & languages) != 0){ - printf("Deep Speech\n"); + strlcat(output,"Deep Speech\r\n",512); } if((INFERNAL & languages) != 0){ - printf("Infernal\n"); + strlcat(output,"Infernal\r\n",512); } if((PRIMORDIAL & languages) != 0){ - printf("Primordial\n"); + strlcat(output,"Primordial\r\n",512); } if((SYLVAN & languages) != 0){ - printf("Sylvan\n"); + strlcat(output,"Sylvan\r\n",512); } if((UNDERCOMMON & languages) != 0){ - printf("Undercommon\n"); + strlcat(output,"Undercommon\r\n",512); } if((DWARVISH & languages) != 0){ - printf("Dwarvish\n"); + strlcat(output,"Dwarvish\r\n",512); } if((ELVISH & languages) != 0){ - printf("Elvish\n"); + strlcat(output,"Elvish\r\n",512); } if((GIANT & languages) != 0){ - printf("Giant\n"); + strlcat(output,"Giant\r\n",512); } if((GNOMISH & languages) != 0){ - printf("Gnome\n"); + strlcat(output,"Gnome\r\n",512); } if((GOBLIN & languages) != 0){ - printf("Goblin\n"); + strlcat(output,"Goblin\r\n",512); } if((HALFLISH & languages) != 0){ - printf("Halfling\n"); + strlcat(output,"Halfling\r\n",512); } if((ORC & languages) != 0){ - printf("Orcish\n"); + strlcat(output,"Orcish\r\n",512); } - printf("\nOther Profs: %s\n", otherprofs); - return 1; + strlcat(output,"\r\nOther Profs: ",512); + strlcat(output,otherprofs,512); + strlcat(output,"\r\n",512); + return output; } diff --git a/character.h b/character.h index be61f63..f255fd1 100644 --- a/character.h +++ b/character.h @@ -80,8 +80,6 @@ #define WIS 4 #define CHA 5 - - unsigned long profs; unsigned long languages; char otherprofs[100]; @@ -95,3 +93,5 @@ char* backgrounds[] = { "Acolyte", "Charlatan", "Criminal", "Entertainer", "Folk int stats[6]; int mods[6]; int hp; + +char* genChar(); diff --git a/chargen.c b/chargen.c index 7834d8e..3182bd9 100644 --- a/chargen.c +++ b/chargen.c @@ -11,6 +11,8 @@ #include #include +#include "character.c" + void usage_and_die(const char *myname, const char *fmt, ...) { if (fmt) @@ -246,7 +248,10 @@ int main(int argc, char **argv) else printf("Responding to packet from %s:%s...\n", hbuf, sbuf); - rval = sendto(s, "chargen data\r\n", 14, 0, sa, len); + //rval = sendto(s, "chargen data\r\n", 14, 0, sa, len); + char character[512]; + genChar(character); + rval = sendto(s, character, 512, 0, sa, len); if (rval == -1) warn("sendto"); } @@ -281,7 +286,9 @@ int main(int argc, char **argv) printf("WTF? i=%u num_stream=%u stream_fds[i]=%d s=%d\n", i, num_stream, stream_fds[i], s); continue; } - if (write(s, "chargen data\r\n", 14) == -1) + char character[512]; + genChar(character); + if (write(s, character, 512) == -1) { warn("write"); printf("Closing stream connection\n");