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{
|
||||
std::vector<User*> people_online;
|
||||
bool peeps{true};
|
||||
libwebsocket * uberclient{nullptr};
|
||||
int peopleuid{0};
|
||||
int balluid{0};
|
||||
|
@ -85,10 +86,12 @@ struct App{
|
|||
void login(User& user){
|
||||
user.index = peopleuid++;
|
||||
people_online.push_back(&user);
|
||||
peeps = true;
|
||||
}
|
||||
|
||||
void logout(User& user){
|
||||
people_online.erase(std::remove(people_online.begin(), people_online.end(), &user), people_online.end());
|
||||
peeps = true;
|
||||
}
|
||||
|
||||
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)
|
||||
[](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()){
|
||||
js::Object ret;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue