Changes

Jump to: navigation, search

UNX511 - 20121 - Project - TeamA

4,431 bytes removed, 22:19, 4 March 2012
organized stuff around
=Development Plan (Rough)=
* Project planning (Jan 11)* Game interface/interaction planning (Jan 18)* Game design/technical programming design (Jan 25)
** C++/OO design
** Socket OO design - accepting connections
** Main game design
** Putting the socket and the main game design together
* R0.1 - basic chat serving capability and in-game displays (Feb. 13)
=Useful Code Snippets=
==Basic HTTP Server==
http://rainulf.ca/files/server.cpp
==HTTP Server Encapsulated in Classes==
Helper.cpp: http://pastebin.com/55pn0wcx <br />
Helper.h: http://pastebin.com/4Ekgbf6d <br />
Web.cpp: http://pastebin.com/MZ9FYxGy <br />
Web.h: http://pastebin.com/k64Kmqy3 <br />
Main.cpp: http://pastebin.com/Z17xSVym <br />
==SQL Schema==<pre> CREATE TABLE unx511* Basic HTTP Server: http://rainulf.avatars ( id int unsigned not null auto_increment, username varchar(20) not null, password varchar(40) not null, level tinyint unsigned not null default 1, lvl_points int unsigned default 0, health int unsigned not null default 100, HP int unsigned not null default 1, cash decimal default 0, banked double default 0, primary key (id)) ENGINE = InnoDB;   CREATE TABLE unx511ca/files/server.avatar_attack (cpp id int unsigned not null auto_increment, attacker_id int unsigned not null, victim_id int unsigned not null, winner int not null, attack_date datetime not null, primary key (id), foreign key (attacker_id) references avatars (id), foreign key (victim_id) references avatars (id)) ENGINE = InnoDB;  CREATE TABLE unx511* Helper.hitlist ( id int unsigned not null auto_increment, placed_hit int unsigned not null, person_to_beat int unsigned not null, amount_paid decimal not null, paid_date datetime not null, active ENUM('Y', 'N') not null, beat_by int unsigned not null, primary key (id), foreign key (placed_hit) references avatars (id), foreign key (person_to_beat) references avatars (id)) ENGINE = InnoDB;  CREATE TABLE unx511cpp: http://pastebin.missions (com/55pn0wcx id int unsigned not null auto_increment, name varchar(256) not null, description varchar(1024), pay_amount decimal not null, score_to_beat int not null, attack_points int not null, defence_points int not null, exp float not null, loot decimal not null, primary key (id)) ENGINE = InnoDB;  CREATE TABLE unx511.item ( id int unsigned not null auto_increment, name varchar(256) not null, attack_points int unsigned null, defence_points int unsigned null, cost decimal unsigned not null, primary key (id)) ENGINE = InnoDB;  CREATE TABLE unx511.avatar_item ( id int unsigned not null auto_increment, avatar_id int unsigned not null, item_id int unsigned not null, amount int not null default 0, # how many of items exist in user inventory amount_paid decimal not null, # is this necessary? since each item has a cost associated with it # date -- if there are multiple items how does date work? primary key (id), foreign key (avatar_id) references avatars (id), foreign key (item_id) references item (id)) ENGINE = InnoDB;  CREATE TABLE unx511* Helper.avatar_mission ( id int unsigned not null auto_increment, avatar_id int unsigned not null, mission_id int unsigned not null, mission_date datetime not null, primary key (id), foreign key (avatar_id) references avatars (id), foreign key (mission_id) references missions (id)) ENGINE = InnoDB; <h: http:/pre>==Common server functions== <pre>/** * Runs a linux command, reallocates memory for whatever the command outputs * @author Rainulf * @return character pointer to the allocated memory * @note needs to be free()'d after use *pastebin.com/4Ekgbf6dchar* runCmd(const char* cmd){ FILE* fp; char* out = NULL; char* more_out; char ch; int count = 0;  /* Open the command for readingWeb. *cpp: http:/ fp = popen(cmd, "r"); if (fp == NULL) { printf("Failed to run command\n" ); return 0; }  /* Read the output a line at a time - output itpastebin. *com/MZ9FYxGy ch = fgetc(fp); while(ch != '\n' && ch != EOF){ more_out = (char*) realloc(out, ++count); Web.h: http:// no need to free more_out  if(more_out != NULL){ out = more_out; out[count-1] = ch; } ch = fgetc(fp); } pclose(fp); return out;} pastebin.com/**k64Kmqy3 * Concatenates two strings by allocating memory for the two * @author Rainulf * @return concatenated string - dynamically allocated * @note needs to be free()'d after use *Main.cpp: http:/char* concat(const char* a, const char* b){ char* tmp = malloc(snprintf(NULL, 0, "%s %s", a, b) + 1); sprintf(tmp, "%s %s", a, b); return tmp;} /** * Gets input from STDIN character by character until '\n' or MAXLEN is reached, puts into the character pointer str * @author Rainulf * @return npastebin.com/aZ17xSVym * @note MAXLEN have to be defined */void getInput(char* str){ int charCount = 0; char ch; Game DB Schema: http:// get input from user ch = getchar(); while( (ch != '\n') && (charCount < MAXLEN) ) { str[charCount++] = ch; ch = getchar(); } str[charCount] = 0;}<pastebin.com/pre>NWKaMLHB
==Text-Based Chat/MUD Client Demo==
 
http://ideone.com/U0gv1
9
edits

Navigation menu