Commit 69a5150f authored by Dennis Willers's avatar Dennis Willers 🏀

Version 1.0

parent 7ede522d
...@@ -4,6 +4,7 @@ author = "RoboTec13" ...@@ -4,6 +4,7 @@ author = "RoboTec13"
category = "Race" category = "Race"
version = "1.0" version = "1.0"
siteid = 120
[script] [script]
imports = ["Icons.as", "Formatting.as"] imports = ["Icons.as", "Formatting.as", "Permissions.as"]
...@@ -36,6 +36,7 @@ void waitingForResponse() { ...@@ -36,6 +36,7 @@ void waitingForResponse() {
} }
void requestSocketServer(const Json::Value &in js) { void requestSocketServer(const Json::Value &in js) {
print("JSON REQUEST: "+ Json::Write(js));
// Send raw data (as a string) to the server. // Send raw data (as a string) to the server.
if (!sock.WriteRaw(Json::Write(js))) { if (!sock.WriteRaw(Json::Write(js))) {
// If this fails, the socket might not be open. Something is wrong! // If this fails, the socket might not be open. Something is wrong!
...@@ -46,6 +47,7 @@ void requestSocketServer(const Json::Value &in js) { ...@@ -46,6 +47,7 @@ void requestSocketServer(const Json::Value &in js) {
void handleMessage(const Json::Value &in js) void handleMessage(const Json::Value &in js)
{ {
print("JSON RESPONSE: "+ Json::Write(js));
if (Json::Write(js) != "null") { if (Json::Write(js) != "null") {
setVotingInformation(js); setVotingInformation(js);
} }
......
string currentChatMessage = ""; string currentChatMessage = "";
void readLastChatMessage() { void readLastChatMessage() {
if (Permissions::InGameChat()) {
while(true) { while(true) {
if (getNetwork() !is null) { if (getNetwork() !is null) {
MwFastBuffer<wstring> chatHistory = getNetwork().ChatHistoryLines; MwFastBuffer<wstring> chatHistory = getNetwork().ChatHistoryLines;
if (chatHistory.get_Length() > 0) { if (chatHistory.Length > 0) {
string chatMessage = chatHistory[0]; string chatMessage = chatHistory[0];
if (chatMessage != currentChatMessage && !hasVoteTimeout) { if (chatMessage != currentChatMessage && !hasVoteTimeout) {
currentChatMessage = chatMessage; currentChatMessage = chatMessage;
...@@ -16,6 +17,7 @@ void readLastChatMessage() { ...@@ -16,6 +17,7 @@ void readLastChatMessage() {
yield(); yield();
} }
} }
}
} }
bool checkIfMessageIsByCurrentClient() { bool checkIfMessageIsByCurrentClient() {
......
...@@ -182,7 +182,7 @@ void newSelectedVoteByChat(int newSelectedValue, int vote) { ...@@ -182,7 +182,7 @@ void newSelectedVoteByChat(int newSelectedValue, int vote) {
void selectValue(int newSelectedValue, int vote, bool isPrintVote) { void selectValue(int newSelectedValue, int vote, bool isPrintVote) {
if (!hasVoteTimeout && selectedValue != newSelectedValue) { if (!hasVoteTimeout && selectedValue != newSelectedValue) {
selectedValue = newSelectedValue; selectedValue = newSelectedValue;
requestSocketServer(jsonBuilderSetVote(vote)); setVoteInformation(vote);
if (isPrintVote) printVote(vote); if (isPrintVote) printVote(vote);
startnew(setVoteTimeout); startnew(setVoteTimeout);
} }
......
Json::Value jsonBuilderSetVote(int vote) { // JSON REQUESTS
Json::Value getVotes() {
auto jsonObj = Json::Object(); auto jsonObj = Json::Object();
jsonObj["vote"] = vote; jsonObj["map"] = getMapUid();
jsonObj["mapId"] = getMapUid(); jsonObj["http"] = "GET";
jsonObj["userId"] = getLogin(); jsonObj["url"] = "getVotes?map="+getMapUid();
jsonObj["name"] = getNameForUi(); return jsonObj;
}
Json::Value getPlayerVote() {
auto jsonObj = Json::Object();
jsonObj["map"] = getMapUid();
jsonObj["http"] = "GET";
jsonObj["url"] = "getPlayerVote?map="+getMapUid()+"&player="+getLogin();
return jsonObj; return jsonObj;
} }
Json::Value jsonBuilderGetMapInfo() { Json::Value setVote(int vote) {
auto jsonObj = Json::Object(); auto jsonObj = Json::Object();
jsonObj["mapId"] = getMapUid(); jsonObj["map"] = getMapUid();
jsonObj["userId"] = getLogin(); jsonObj["http"] = "POST";
jsonObj["name"] = getNameForUi(); jsonObj["player"] = getLogin();
jsonObj["vote"] = vote;
return jsonObj; return jsonObj;
} }
void getMapInitInformation() {
requestSocketServer(getVotes());
requestSocketServer(getPlayerVote());
}
void setVoteInformation(int vote) {
requestSocketServer(setVote(vote));
}
\ No newline at end of file
...@@ -31,7 +31,7 @@ void Main() ...@@ -31,7 +31,7 @@ void Main()
void loadMapVoteInfo() { void loadMapVoteInfo() {
if (initSocketConnection()) { if (initSocketConnection()) {
requestSocketServer(jsonBuilderGetMapInfo()); getMapInitInformation();
resetTimeout(); resetTimeout();
currentMapUid = getMapUid(); currentMapUid = getMapUid();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment