Sending people to the uberclient
This commit is contained in:
parent
7645bdbe3a
commit
c523e9d296
2 changed files with 17 additions and 1 deletions
|
@ -16,6 +16,7 @@ using namespace websockets;
|
||||||
|
|
||||||
struct App{
|
struct App{
|
||||||
std::vector<User*> people_online;
|
std::vector<User*> people_online;
|
||||||
|
bool peeps{true};
|
||||||
libwebsocket * uberclient{nullptr};
|
libwebsocket * uberclient{nullptr};
|
||||||
int peopleuid{0};
|
int peopleuid{0};
|
||||||
int balluid{0};
|
int balluid{0};
|
||||||
|
@ -85,10 +86,12 @@ struct App{
|
||||||
void login(User& user){
|
void login(User& user){
|
||||||
user.index = peopleuid++;
|
user.index = peopleuid++;
|
||||||
people_online.push_back(&user);
|
people_online.push_back(&user);
|
||||||
|
peeps = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void logout(User& user){
|
void logout(User& user){
|
||||||
people_online.erase(std::remove(people_online.begin(), people_online.end(), &user), people_online.end());
|
people_online.erase(std::remove(people_online.begin(), people_online.end(), &user), people_online.end());
|
||||||
|
peeps = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(){
|
void update(){
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -83,6 +83,19 @@ websockets::TestProtocol<Empty> uberclient_protocol{
|
||||||
},
|
},
|
||||||
// write (will always come after receive)
|
// write (will always come after receive)
|
||||||
[](Empty& user, basic_websocket_info) -> std::string{
|
[](Empty& user, basic_websocket_info) -> std::string{
|
||||||
|
if(app->peeps){
|
||||||
|
app->peeps = false;
|
||||||
|
std::string str;
|
||||||
|
for(auto & u : app->people_online){
|
||||||
|
str += u->name;
|
||||||
|
if(u != app->people_online.back())
|
||||||
|
str += ", ";
|
||||||
|
}
|
||||||
|
js::Object ret;
|
||||||
|
ret["command"] = "peeps";
|
||||||
|
ret["data"] = to_json(str);
|
||||||
|
return write_json(ret);
|
||||||
|
}
|
||||||
if(!app->offline_sim.lines_to_remove.empty()){
|
if(!app->offline_sim.lines_to_remove.empty()){
|
||||||
js::Object ret;
|
js::Object ret;
|
||||||
ret["command"] = "remove lines";
|
ret["command"] = "remove lines";
|
||||||
|
@ -118,7 +131,7 @@ websockets::TestProtocol<Empty> uberclient_protocol{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!app->offline_sim.lines_to_add.empty() || !app->offline_sim.lines_to_remove.empty()){
|
if(app->peeps || !app->offline_sim.lines_to_add.empty() || !app->offline_sim.lines_to_remove.empty()){
|
||||||
request_write(binfo);
|
request_write(binfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue