Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetClient.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | void CNetClient::PostPlayerAssignmentsToScript() | ||||
GetScriptInterface().Eval("({'type':'players', 'newAssignments':{}})", &msg); | GetScriptInterface().Eval("({'type':'players', 'newAssignments':{}})", &msg); | ||||
JS::RootedValue newAssignments(cx); | JS::RootedValue newAssignments(cx); | ||||
GetScriptInterface().GetProperty(msg, "newAssignments", &newAssignments); | GetScriptInterface().GetProperty(msg, "newAssignments", &newAssignments); | ||||
for (const std::pair<CStr, PlayerAssignment>& p : m_PlayerAssignments) | for (const std::pair<CStr, PlayerAssignment>& p : m_PlayerAssignments) | ||||
{ | { | ||||
JS::RootedValue assignment(cx); | JS::RootedValue assignment(cx); | ||||
GetScriptInterface().Eval("({})", &assignment); | |||||
GetScriptInterface().SetProperty(assignment, "name", CStrW(p.second.m_Name), false); | GetScriptInterface().CreateObject( | ||||
GetScriptInterface().SetProperty(assignment, "player", p.second.m_PlayerID, false); | &assignment, | ||||
GetScriptInterface().SetProperty(assignment, "status", p.second.m_Status, false); | "name", CStrW(p.second.m_Name), | ||||
GetScriptInterface().SetProperty(newAssignments, p.first.c_str(), assignment, false); | "player", p.second.m_PlayerID, | ||||
"status", p.second.m_Status); | |||||
GetScriptInterface().SetProperty(newAssignments, p.first.c_str(), assignment); | |||||
} | } | ||||
PushGuiMessage(msg); | PushGuiMessage(msg); | ||||
} | } | ||||
bool CNetClient::SendMessage(const CNetMessage* message) | bool CNetClient::SendMessage(const CNetMessage* message) | ||||
{ | { | ||||
if (!m_Session) | if (!m_Session) | ||||
▲ Show 20 Lines • Show All 444 Lines • ▼ Show 20 Lines | bool CNetClient::OnKicked(void *context, CFsmEvent* event) | ||||
CNetClient* client = (CNetClient*)context; | CNetClient* client = (CNetClient*)context; | ||||
JSContext* cx = client->GetScriptInterface().GetContext(); | JSContext* cx = client->GetScriptInterface().GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
CKickedMessage* message = (CKickedMessage*)event->GetParamRef(); | CKickedMessage* message = (CKickedMessage*)event->GetParamRef(); | ||||
JS::RootedValue msg(cx); | JS::RootedValue msg(cx); | ||||
client->GetScriptInterface().Eval("({})", &msg); | client->GetScriptInterface().CreateObject( | ||||
client->GetScriptInterface().SetProperty(msg, "username", message->m_Name); | &msg, | ||||
client->GetScriptInterface().SetProperty(msg, "type", CStr("kicked")); | "username", message->m_Name, | ||||
client->GetScriptInterface().SetProperty(msg, "banned", message->m_Ban != 0); | "type", CStr("kicked"), | ||||
"banned", message->m_Ban != 0); | |||||
client->PushGuiMessage(msg); | client->PushGuiMessage(msg); | ||||
return true; | return true; | ||||
} | } | ||||
bool CNetClient::OnClientTimeout(void *context, CFsmEvent* event) | bool CNetClient::OnClientTimeout(void *context, CFsmEvent* event) | ||||
{ | { | ||||
// Report the timeout of some other client | // Report the timeout of some other client | ||||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator