Skip to content

Commit

Permalink
First attempt at chart requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Nov 26, 2018
1 parent b44b6d5 commit 58ad984
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/NetworkSyncManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ std::map<std::string, ETTServerMessageTypes> ettServerMessageMap = {
{ "newroom", ettps_newroom },
{ "updateroom", ettps_updateroom },
{ "userlist", ettps_roomuserlist },
{ "chartrequest", ettps_chartrequest }
};

#if defined(WITHOUT_NETWORKING)
Expand Down Expand Up @@ -915,6 +916,9 @@ ETTProtocol::Update(NetworkSyncManager* n, float fDeltaTime)
SCREENMAN->SetNewScreen(SMOnlineSelectScreen);
}
} break;
case ettps_chartrequest: {
n->requests.emplace_back(ChartRequest(*payload));
} break;
case ettps_enterroomresponse: {
bool entered = (*payload)["entered"];
inRoom = false;
Expand Down Expand Up @@ -2482,6 +2486,18 @@ NetworkSyncManager::GetCurrentSMBuild(LoadingWindow* ld)
}
#endif

void
ChartRequest::PushSelf(lua_State* L)
{
lua_createtable(L, 0, 3);
lua_pushstring(L, chartkey.c_str());
lua_setfield(L, -2, "chartkey");
lua_pushstring(L, user.c_str());
lua_setfield(L, -2, "user");
lua_pushnumber(L, rate / 1000); // should this be in [0,1] or [0, 1000] ????
lua_setfield(L, -2, "rate");
}

static bool
ConnectToServer(const RString& t)
{
Expand Down Expand Up @@ -2527,6 +2543,18 @@ LuaFunction(IsSMOnlineLoggedIn, NSMAN->loggedIn)
lua_pushboolean(L, p->IsETTP());
return 1;
}
static int GetChartRequests(T* p, lua_State* L)
{
auto& reqs = p->requests;
lua_newtable(L);
int i = 1;
for (auto& req : reqs) {
req.PushSelf(L);
lua_rawseti(L, -2, 0);
i++;
}
return 1;
}
static int GetChatMsg(T* p, lua_State* L)
{
unsigned int l = IArg(1);
Expand Down
17 changes: 17 additions & 0 deletions src/NetworkSyncManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum ETTServerMessageTypes
ettps_newroom,
ettps_updateroom,
ettps_roomuserlist,
ettps_chartrequest,
ettps_end
};
enum ETTClientMessageTypes
Expand Down Expand Up @@ -132,6 +133,21 @@ struct NetServerInfo
RString Address;
};

class ChartRequest
{
public:
ChartRequest(json& j)
: chartkey(j["chartkey"].get<string>())
, user(j["requester"].get<string>())
, rate(j["rate"])
{
}
const string chartkey;
const string user; // User that requested this chart
const int rate; // rate * 1000
void PushSelf(lua_State* L);
};

class EzSockets;
class StepManiaLanServer;

Expand Down Expand Up @@ -457,6 +473,7 @@ class NetworkSyncManager
void Login(RString user, RString pass);
void Logout();
vector<RoomData> m_Rooms;
vector<ChartRequest> requests;

#if !defined(WITHOUT_NETWORKING)
SMOStepType TranslateStepType(int score);
Expand Down

0 comments on commit 58ad984

Please sign in to comment.