client specific communication - now multiple clients can connect simulteneously
This commit is contained in:
17
Server.pde
17
Server.pde
@@ -1,43 +1,42 @@
|
||||
|
||||
String s_map[]; //send this via tcp
|
||||
|
||||
int i_citizenTransferC;
|
||||
void clientCommunication() {
|
||||
client = server.available();
|
||||
if (client != null) {
|
||||
s_fromClient = client.readString();
|
||||
if (s_fromClient.equals("give citizenC")) {
|
||||
server.write(str(citizen.length));
|
||||
client.write(str(citizen.length));
|
||||
}
|
||||
if (s_fromClient.equals("give citizen")) {
|
||||
if(i_citizenTransferC >= citizen.length) i_citizenTransferC = 0;
|
||||
server.write("Name: " + citizen[i_citizenTransferC].s_name + ", Gender: " + citizen[i_citizenTransferC].s_gender + ", Age: " + str(citizen[i_citizenTransferC].i_age) + ", Currently doing: " + citizen[i_citizenTransferC].s_currentAction);
|
||||
client.write("Name: " + citizen[i_citizenTransferC].s_name + ", Gender: " + citizen[i_citizenTransferC].s_gender + ", Age: " + str(citizen[i_citizenTransferC].i_age) + ", Currently doing: " + citizen[i_citizenTransferC].s_currentAction);
|
||||
i_citizenTransferC++;
|
||||
}
|
||||
if (s_fromClient.contains("give locx")) {
|
||||
String[] list = split(s_fromClient, ':');
|
||||
int requestedCitizen = int(list[1]);
|
||||
server.write(str(citizen[requestedCitizen].f_xPos/i_sMapReso));
|
||||
client.write(str(citizen[requestedCitizen].f_xPos/i_sMapReso));
|
||||
}
|
||||
if (s_fromClient.contains("give locy")) {
|
||||
String[] list = split(s_fromClient, ':');
|
||||
int requestedCitizen = int(list[1]);
|
||||
server.write(str(citizen[requestedCitizen].f_yPos/i_sMapReso));
|
||||
client.write(str(citizen[requestedCitizen].f_yPos/i_sMapReso));
|
||||
}
|
||||
if (s_fromClient.contains("give a")) {
|
||||
String[] list = split(s_fromClient, ':');
|
||||
int requestedCitizen = int(list[1]);
|
||||
server.write(str(citizen[requestedCitizen].f_angle));
|
||||
client.write(str(citizen[requestedCitizen].f_angle));
|
||||
}
|
||||
if (s_fromClient.equals("give mapw")) {
|
||||
server.write(str(img_houses.width/i_sMapReso));
|
||||
client.write(str(img_houses.width/i_sMapReso));
|
||||
}
|
||||
if (s_fromClient.equals("give maph")) {
|
||||
server.write(str(img_houses.height/i_sMapReso));
|
||||
client.write(str(img_houses.height/i_sMapReso));
|
||||
}
|
||||
if (i_mapLevelTransferC >= img_houses.height/i_sMapReso) i_mapLevelTransferC = 0;
|
||||
if (s_fromClient.equals("give map")) {
|
||||
server.write(s_map[i_mapLevelTransferC]);
|
||||
client.write(s_map[i_mapLevelTransferC]);
|
||||
i_mapLevelTransferC++;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -94,9 +94,8 @@ int main(){
|
||||
tcgetattr(STDIN_FILENO, &ttystate);
|
||||
ttystate.c_lflag &= (~ICANON & ~ECHO); //not display character || is this in conflict with what ncurses does in keyListener()?
|
||||
ttystate.c_cc[VMIN] = 1;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate); */
|
||||
fputs("\e[?25h", stdout); //show cursor agein
|
||||
fputs("\e[?25l", stdout); //remove cursor */
|
||||
system("kbdrate -d 250 -r 10");
|
||||
struct winsize size;
|
||||
ioctl(STDOUT_FILENO,TIOCGWINSZ,&size);
|
||||
@@ -169,8 +168,8 @@ int main(){
|
||||
char bufferMap[4096] = {0};
|
||||
send(sock , mapRequest , strlen(mapRequest) , 0 );
|
||||
int getmap = read( sock , bufferMap, 4096);
|
||||
map += ("%s\n",bufferMap ); //IS THIS WHERE IT BECOMES BROKEN!???!?!??!?! I THINK SO
|
||||
map.pop_back(); //OR THIS! CAN BE FIXED BY KILLING THE BUG ABOVE
|
||||
map += ("%s\n",bufferMap );
|
||||
map.pop_back();
|
||||
}
|
||||
|
||||
//PREPARE MINIMAP
|
||||
@@ -188,6 +187,10 @@ int main(){
|
||||
auto tp1 = clock::now();
|
||||
auto tp2 = clock::now();
|
||||
|
||||
|
||||
|
||||
|
||||
fputs("\e[?25l", stdout); //remove cursor
|
||||
///////////////////////////////////////////////////////////
|
||||
////////BEGINDRAW/////
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user