forked from oerkki/voxelands
some http and html updates
This commit is contained in:
parent
3826500a31
commit
1081151c6a
|
@ -3,23 +3,24 @@
|
|||
<head>
|
||||
<title>Voxelands</title>
|
||||
<style type="text/css">
|
||||
html, body {background:#323246; color:#F0F0F0; font: 14px sans-serif; line-height:1.2em; position:relative; min-width:100%; min-height:100%; margin:0; padding:0;}
|
||||
html {background:#050505; color:#FFFFFF; font: 14px monospace; line-height:1.2em; position:relative; width:100%; height:100%; margin:0; padding:0;}
|
||||
body {margin:0; padding:0; background:#7777ED url(http://www.voxelands.com/images/background.jpg) no-repeat 50% 100% fixed; position:relative; min-height:100%;}
|
||||
|
||||
header.site-header {display:block; margin:0; padding:0; background:#1E1E32; color:#101010; height:50px;}
|
||||
header.site-header {display:block; margin:0; padding:0; background:#1E1E32; background-color:rgba(30,30,50,0.8); color:#101010; height:50px;}
|
||||
header.site-header div.main-header {display:block; margin:0 auto; padding:0; width:1000px; height:50px; position:relative;}
|
||||
header.site-header h1 {display:block; line-height:50px; margin:0; padding:0; width:300px; font-weight:bold; font-size:20px; background:transparent; color:#C0C0C0; text-align:center; float:left;}
|
||||
header.site-header h1 {display:block; line-height:50px; margin:0; padding:0; width:300px; font-weight:bold; font-size:20px; background:transparent; color:#FFFFFF; text-align:center; float:left;}
|
||||
header.site-header nav {display:block; float:left; margin:0; padding:0; height:50px; width:600px;}
|
||||
header.site-header nav ul {display:block; float:left; margin:0; padding:0; height:50px; width:600px; list-style-type:none;}
|
||||
header.site-header nav ul li {display:block; float:left; margin:0; padding:0; text-align:center;}
|
||||
header.site-header nav ul li a {display:block; float:left; margin:0; padding:0 10px; height:50px; line-height:50px; background:transparent; color:#A5A5A5; text-decoration:none; font-size:16px; font-weight:bold;}
|
||||
header.site-header nav ul li a:hover {line-height:42px; height:42px; border-top:4px solid #1E1E32; border-bottom:4px solid #616161; border-left:none; border-right:none;}
|
||||
header.site-header nav ul li a {display:block; float:left; margin:0; padding:0 10px; height:50px; line-height:50px; background:transparent; color:#FFFFFF; text-decoration:none; font-size:16px; font-weight:bold;}
|
||||
header.site-header nav ul li a:hover {line-height:42px; height:42px; margin-top:4px; border-bottom:4px solid #FFFFF0; border-left:none; border-right:none;}
|
||||
|
||||
div.body {margin:0 auto; width:1000px; min-height:80%; padding:20px 0; position:relative; height:auto; overflow:hidden;}
|
||||
|
||||
div.body div.panel {background:#1E1E32; color:#C0C0C0; margin:10px; padding:10px; border:1px solid #3C3C50; height:auto; overflow:hidden;}
|
||||
div.body div.panel {background:#1E1E32; background-color:rgba(30,30,50,0.7); color:#FFFFFF; margin:10px; padding:10px; border:1px solid #3C3C50; height:auto; overflow:hidden;}
|
||||
div.body div.panel img {margin:10px;}
|
||||
|
||||
div.body div.panel a.secret {color:#C0C0C0; text-decoration:none;}
|
||||
div.body div.panel a.secret {color:#FFFFFF; text-decoration:none;}
|
||||
|
||||
div.body h1 {text-align:center; font-size:20px; font-weight:bold; margin:0; margin-bottom:20px; padding:0;}
|
||||
div.body h2 {text-align:left; font-size:18px; font-weight:bold; margin:0; margin-bottom:20px; padding:0;}
|
||||
|
@ -28,6 +29,9 @@ div.body ul {list-style-type:square;}
|
|||
div.body ul, div.body ol {margin:0; padding:0; padding-left:15px;}
|
||||
div.body ul li, div.body ol li {margin:0; padding:0; margin-bottom:5px;}
|
||||
|
||||
div.body div.pagination {display:block; margin:10px; text-align:right;}
|
||||
div.body div.pagination a {color:#FFFFFF;}
|
||||
|
||||
.green {color:#0EAB13;}
|
||||
.red {color:#AB0E1B;}
|
||||
.bold {font-weight:bold;}
|
||||
|
|
|
@ -727,8 +727,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
// Send as reliable
|
||||
m_con.Send(PEER_ID_SERVER, 1, data, true);
|
||||
}
|
||||
sendWantCookie();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -927,8 +925,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
infostream<<"Client: Adding new player "<<peer_id<<std::endl;
|
||||
}
|
||||
player->updateName((char*)&data[start+2]);
|
||||
std::string p_name((char*)&data[start+2]);
|
||||
m_httpclient->pushRequest(HTTPREQUEST_SKIN_HASH,p_name);
|
||||
start += item_size;
|
||||
}
|
||||
/*
|
||||
|
@ -1012,8 +1008,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
|
||||
player->setCharDef(chardef);
|
||||
player->updateName(pname);
|
||||
std::string p_name(pname);
|
||||
m_httpclient->pushRequest(HTTPREQUEST_SKIN_HASH,p_name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1550,26 +1544,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
m_client_event_queue.push_back(event);
|
||||
}
|
||||
break;
|
||||
case TOCLIENT_HAVECOOKIE:
|
||||
{
|
||||
/*
|
||||
u16 command
|
||||
u16 textlen
|
||||
textdata
|
||||
*/
|
||||
std::string datastring((char*)&data[2], datasize-2);
|
||||
std::istringstream is(datastring, std::ios_base::binary);
|
||||
|
||||
u16 len = readU16(is);
|
||||
char buff[len+1];
|
||||
is.read(buff,len);
|
||||
buff[len] = 0;
|
||||
std::string c(buff);
|
||||
std::string p(getLocalPlayer()->getName());
|
||||
m_httpclient->setCookie(c);
|
||||
m_httpclient->pushRequest(HTTPREQUEST_SKIN_HASH,p);
|
||||
}
|
||||
break;
|
||||
case TOCLIENT_ENV_EVENT:
|
||||
{
|
||||
/*
|
||||
|
@ -1898,19 +1872,6 @@ void Client::sendRespawn()
|
|||
Send(0, data, true);
|
||||
}
|
||||
|
||||
void Client::sendWantCookie()
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
writeU16(os, TOSERVER_WANTCOOKIE);
|
||||
|
||||
// Make data buffer
|
||||
std::string s = os.str();
|
||||
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
|
||||
// Send as reliable
|
||||
Send(0, data, true);
|
||||
}
|
||||
|
||||
void Client::sendPlayerPos()
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
|
|
@ -219,7 +219,6 @@ public:
|
|||
void sendDamage(s8 damage, s8 suffocate, s8 hunger);
|
||||
void sendClothesWear(u16 wear);
|
||||
void sendRespawn();
|
||||
void sendWantCookie();
|
||||
|
||||
ClientEnvironment& getEnv() { return m_env; }
|
||||
|
||||
|
|
|
@ -194,13 +194,6 @@ enum ToClientCommand
|
|||
v3f1000 camera point target (to point the death cause or whatever)
|
||||
*/
|
||||
|
||||
TOCLIENT_HAVECOOKIE = 0x38,
|
||||
/*
|
||||
u16 command
|
||||
u16 textlen
|
||||
textdata
|
||||
*/
|
||||
|
||||
TOCLIENT_PLAYERITEMS = 0x39,
|
||||
/*
|
||||
u16 command
|
||||
|
@ -427,11 +420,6 @@ enum ToServerCommand
|
|||
u16 TOSERVER_RESPAWN
|
||||
*/
|
||||
|
||||
TOSERVER_WANTCOOKIE=0x39,
|
||||
/*
|
||||
u16 TOSERVER_WANTCOOKIE
|
||||
*/
|
||||
|
||||
TOSERVER_NODEMETA_FIELDS = 0x3b,
|
||||
/*
|
||||
u16 command
|
||||
|
|
359
src/http.cpp
359
src/http.cpp
|
@ -46,9 +46,9 @@ static std::string http_player_interface(Player *player, HTTPServer *server, boo
|
|||
html += player->getName();
|
||||
html += "</a></h2>";
|
||||
if (full) {
|
||||
html += "<p class=\"right\"><img src=\"/player/";
|
||||
html += player->getName();
|
||||
html += "/skin\" /></p>";
|
||||
//html += "<p class=\"right\"><img src=\"/player/";
|
||||
//html += player->getName();
|
||||
//html += "/skin\" /></p>";
|
||||
}
|
||||
snprintf(buff, 2048,"% .1f, % .1f, % .1f",player->getPosition().X/BS,player->getPosition().Y/BS,player->getPosition().Z/BS);
|
||||
if (player->peer_id == 0) {
|
||||
|
@ -188,13 +188,6 @@ int HTTPRemoteClient::receive()
|
|||
if (h == -1)
|
||||
return 1;
|
||||
|
||||
if (m_recv_headers.getCookie() != "" && m_recv_headers.getHeader("User") != "") {
|
||||
if (m_recv_headers.getCookie() == m_server->getPlayerCookie(m_recv_headers.getHeader("User"))) {
|
||||
m_send_headers.setCookie(m_recv_headers.getCookie());
|
||||
m_auth = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_recv_headers.getUrl(0) == "texture") {
|
||||
return handleTexture();
|
||||
}else if (m_recv_headers.getUrl(0) == "player") {
|
||||
|
@ -209,101 +202,50 @@ int HTTPRemoteClient::receive()
|
|||
/* handle /player/<name> url's */
|
||||
int HTTPRemoteClient::handlePlayer()
|
||||
{
|
||||
char buff[2048];
|
||||
/* player list */
|
||||
if (m_recv_headers.getUrl(1) == "") {
|
||||
std::string u1 = m_recv_headers.getUrl(1);
|
||||
if (u1 == "" || u1.substr(0,5) == "page-") {
|
||||
core::list<Player*> players = m_server->getGameServer()->getPlayers();
|
||||
std::string html("<h1>Players</h1>\n");
|
||||
for (core::list<Player*>::Iterator i = players.begin(); i != players.end(); i++) {
|
||||
std::string pagination("");
|
||||
int player_skip = 0;
|
||||
if (players.size() > 50) {
|
||||
int current_page = 1;
|
||||
if (u1.substr(0,5) == "page-") {
|
||||
current_page = mystoi(u1.substr(5));
|
||||
if (current_page < 1)
|
||||
current_page = 1;
|
||||
}
|
||||
int total_pages = (players.size()/50)+1;
|
||||
if (total_pages < 1)
|
||||
total_pages = 1;
|
||||
if (current_page > total_pages)
|
||||
current_page = total_pages;
|
||||
int prev_page = current_page-1;
|
||||
int next_page = current_page+1;
|
||||
if (prev_page < 1)
|
||||
prev_page = 1;
|
||||
if (next_page > total_pages)
|
||||
next_page = total_pages;
|
||||
pagination = std::string("<div class=\"pagination\"><a href=\"/player/page-")+itos(prev_page)+"\"><< prev</a> ";
|
||||
pagination += std::string("Page ")+itos(current_page)+" of "+itos(total_pages)+" ";
|
||||
pagination += std::string("<a class=\"pagination\" href=\"/player/page-")+itos(next_page)+"\">next >></a></div>";
|
||||
player_skip = (current_page-1)*50;
|
||||
}
|
||||
html += pagination;
|
||||
int p = 0;
|
||||
for (core::list<Player*>::Iterator i = players.begin(); i != players.end(); i++,p++) {
|
||||
if (p < player_skip)
|
||||
continue;
|
||||
if (p > player_skip+50)
|
||||
break;
|
||||
Player *player = *i;
|
||||
html += http_player_interface(player,m_server,false);
|
||||
}
|
||||
html += pagination;
|
||||
sendHTML((char*)html.c_str());
|
||||
return 1;
|
||||
/* player skin */
|
||||
}else if (m_recv_headers.getUrl(2) == "skin") {
|
||||
std::string file = getPath("player","player_" + m_recv_headers.getUrl(1) + ".png",true);
|
||||
if (m_recv_headers.getMethod() != "PUT") {
|
||||
if (file == "") {
|
||||
if (m_auth && m_recv_headers.getHeader("User") == m_recv_headers.getUrl(1))
|
||||
return handleSpecial("304 Not Modified");
|
||||
if (m_recv_headers.getUrl(3) == "hash")
|
||||
return handleSpecial("204 No Content");
|
||||
m_send_headers.setHeader("Location","/texture/character.png");
|
||||
return handleSpecial("303 See Other","<p><a href=\"/texture/character.png\">/texture/character.png</a></p>");
|
||||
}
|
||||
/* compare hash */
|
||||
if (m_recv_headers.getUrl(3) == "hash") {
|
||||
FILE *f;
|
||||
f = fopen(file.c_str(),"rb");
|
||||
if (!f) {
|
||||
if (m_auth && m_recv_headers.getHeader("User") == m_recv_headers.getUrl(1))
|
||||
return handleSpecial("304 Not Modified");
|
||||
return handleSpecial("204 No Content");
|
||||
}
|
||||
fseek(f,0,SEEK_END);
|
||||
size_t l = ftell(f);
|
||||
fclose(f);
|
||||
if (!l) {
|
||||
if (m_auth && m_recv_headers.getHeader("User") == m_recv_headers.getUrl(1))
|
||||
return handleSpecial("304 Not Modified");
|
||||
return handleSpecial("204 No Content");
|
||||
}
|
||||
SHA1 s;
|
||||
s.addFile(file.c_str());
|
||||
s.getDigest(buff);
|
||||
if (std::string(buff) == m_recv_headers.getUrl(4)) {
|
||||
return handleSpecial("204 No Content");
|
||||
}else if (m_auth && m_recv_headers.getHeader("User") == m_recv_headers.getUrl(1)) {
|
||||
return handleSpecial("304 Not Modified");
|
||||
}
|
||||
}
|
||||
/* get file */
|
||||
m_send_headers.setHeader("Content-Type","image/png");
|
||||
sendFile(file);
|
||||
return 1;
|
||||
}
|
||||
if (file == "")
|
||||
file = getPath("player","player_" + m_recv_headers.getUrl(1) + ".png",false);
|
||||
fs::CreateAllDirs(getPath("dir",std::string("textures")+DIR_DELIM+"players",false));
|
||||
/* put only works for the owner */
|
||||
if (!m_auth || m_recv_headers.getHeader("User") != m_server->getPlayerFromCookie(m_recv_headers.getCookie()))
|
||||
return handleSpecial("405 Method Not Allowed");
|
||||
size_t s = m_recv_headers.getLength();
|
||||
if (!s)
|
||||
return handleSpecial("411 Length Required");
|
||||
FILE *f;
|
||||
f = fopen(file.c_str(),"wb");
|
||||
if (!f)
|
||||
return handleSpecial("500 Internal Server Error");
|
||||
size_t l;
|
||||
size_t c = 2048;
|
||||
size_t t = 0;
|
||||
if (c > s)
|
||||
c = s;
|
||||
if (c) {
|
||||
while ((l = read(buff,c)) > 0) {
|
||||
s -= l;
|
||||
t += l;
|
||||
c = fwrite(buff,1,l,f);
|
||||
if (c != l) {
|
||||
fclose(f);
|
||||
return handleSpecial("500 Internal Server Error");
|
||||
}
|
||||
c = 2048;
|
||||
if (c > s)
|
||||
c = s;
|
||||
if (!c)
|
||||
break;
|
||||
}
|
||||
}
|
||||
l = ftell(f);
|
||||
fclose(f);
|
||||
if (l == t && l == m_recv_headers.getLength())
|
||||
return handleSpecial("201 Created");
|
||||
fs::RecursiveDelete(file.c_str());
|
||||
return handleSpecial("500 Internal Server Error");
|
||||
}else if (m_server->getGameServer()->getPlayer(m_recv_headers.getUrl(1))) {
|
||||
}else if (m_server->getGameServer()->getPlayer(u1)) {
|
||||
std::string html("<h1>Players</h1>\n");
|
||||
Player *player = m_server->getGameServer()->getPlayer(m_recv_headers.getUrl(1));
|
||||
html += http_player_interface(player,m_server,true);
|
||||
|
@ -324,17 +266,6 @@ int HTTPRemoteClient::handleTexture()
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* handle /model/<file> url's */
|
||||
int HTTPRemoteClient::handleModel()
|
||||
{
|
||||
std::string file = getPath("model",m_recv_headers.getUrl(1),true);
|
||||
if (file == "")
|
||||
return handleSpecial("404 Not Found");
|
||||
m_send_headers.setHeader("Content-Type","application/octet-stream");
|
||||
sendFile(file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* handle /map/<x>/<y>/<z> url's */
|
||||
int HTTPRemoteClient::handleMap()
|
||||
{
|
||||
|
@ -464,7 +395,6 @@ void HTTPRemoteClient::sendFile(std::string &file)
|
|||
t += l;
|
||||
m_socket->Send(buff,l);
|
||||
}
|
||||
//printf("sent: %lu %lu\n",s,t);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
@ -496,12 +426,6 @@ void HTTPRemoteClient::sendHeaders()
|
|||
s = snprintf(buff,1024,"Content-Length: %d\r\n",s);
|
||||
m_socket->Send(buff,s);
|
||||
|
||||
v = m_send_headers.getCookie();
|
||||
if (v != "") {
|
||||
s = snprintf(buff,1024,"Set-Cookie: MTID=%s\r\n",v.c_str());
|
||||
m_socket->Send(buff,s);
|
||||
}
|
||||
|
||||
v = m_send_headers.getHeader("Location");
|
||||
if (v != "") {
|
||||
s = snprintf(buff,1024,"Location: %s\r\n",v.c_str());
|
||||
|
@ -550,7 +474,6 @@ void * HTTPClientThread::Thread()
|
|||
|
||||
/* constructor */
|
||||
HTTPClient::HTTPClient(Client *client):
|
||||
m_cookie(""),
|
||||
m_thread(this)
|
||||
{
|
||||
m_client = client;
|
||||
|
@ -592,11 +515,7 @@ void HTTPClient::stop()
|
|||
/* the main function for the client loop */
|
||||
void HTTPClient::step()
|
||||
{
|
||||
if (m_requests.size() == 0 || m_cookie == "") {
|
||||
/* this should only happen if a packet was lost
|
||||
* or the server has enable_http = false */
|
||||
//if (m_requests.size() > 0 || m_cookie == "")
|
||||
//m_client->sendWantCookie();
|
||||
if (m_requests.size() == 0) {
|
||||
#ifdef _WIN32
|
||||
Sleep(1000);
|
||||
#else
|
||||
|
@ -639,11 +558,7 @@ void HTTPClient::step()
|
|||
m_recv_headers.clear();
|
||||
m_send_headers.clear();
|
||||
|
||||
if (q.post == "") {
|
||||
get(q.url);
|
||||
}else{
|
||||
put(q.url,q.post);
|
||||
}
|
||||
get(q.url);
|
||||
|
||||
int r = 0;
|
||||
int h = -1;
|
||||
|
@ -658,70 +573,6 @@ void HTTPClient::step()
|
|||
}
|
||||
|
||||
r = m_recv_headers.getResponse();
|
||||
|
||||
if (q.post == "") {
|
||||
if (r == 204 || r == 303) {
|
||||
delete m_socket;
|
||||
continue;
|
||||
}else if (r == 304) {
|
||||
std::string d(m_client->getLocalPlayer()->getName());
|
||||
pushRequest(HTTPREQUEST_SKIN_SEND,d);
|
||||
delete m_socket;
|
||||
continue;
|
||||
}
|
||||
if (r != 200) {
|
||||
errorstream << "receive skin returned " << r << std::endl;
|
||||
delete m_socket;
|
||||
continue;
|
||||
}
|
||||
if (q.data == "") {
|
||||
errorstream << "receive skin returned successful for no player?" << std::endl;
|
||||
delete m_socket;
|
||||
continue;
|
||||
}
|
||||
if (q.data == m_client->getLocalPlayer()->getName()) {
|
||||
delete m_socket;
|
||||
continue;
|
||||
}
|
||||
char buff[2048];
|
||||
fs::CreateAllDirs(getPath("dir",std::string("textures")+DIR_DELIM+"players",false));
|
||||
std::string file = getPath("player",std::string("player_")+q.data+".png",false);
|
||||
size_t s = m_recv_headers.getLength();
|
||||
if (!s) {
|
||||
delete m_socket;
|
||||
continue;
|
||||
}
|
||||
FILE *f;
|
||||
f = fopen(file.c_str(),"wb");
|
||||
if (!f) {
|
||||
delete m_socket;
|
||||
continue;
|
||||
}
|
||||
size_t l;
|
||||
size_t c = 2048;
|
||||
if (c > s)
|
||||
c = s;
|
||||
if (c) {
|
||||
m_socket->WaitData(60000);
|
||||
while ((l = read(buff,c)) > 0) {
|
||||
s -= l;
|
||||
c = fwrite(buff,1,l,f);
|
||||
if (c != l)
|
||||
break;
|
||||
c = 2048;
|
||||
if (c > s)
|
||||
c = s;
|
||||
if (!c)
|
||||
break;
|
||||
}
|
||||
}
|
||||
l = ftell(f);
|
||||
fclose(f);
|
||||
if (l != m_recv_headers.getLength())
|
||||
fs::RecursiveDelete(file.c_str());
|
||||
}else if (r == 405) {
|
||||
errorstream << "send skin returned 405 Method Not Allowed" << std::endl;
|
||||
}
|
||||
delete m_socket;
|
||||
}
|
||||
p.clear();
|
||||
|
@ -735,89 +586,6 @@ void HTTPClient::pushRequest(HTTPRequestType type, std::string &data)
|
|||
switch (type) {
|
||||
case HTTPREQUEST_NULL:
|
||||
break;
|
||||
/*
|
||||
* /player/<name>/skin
|
||||
* request the skin texture for <name>
|
||||
* response:
|
||||
* if skin exists:
|
||||
* 200 OK + texture data
|
||||
* else:
|
||||
* 303 See Other + Location header to /texture/character.png
|
||||
* this client will ignore the redirect, while browsers will see the default skin
|
||||
*/
|
||||
case HTTPREQUEST_SKIN:
|
||||
{
|
||||
std::string url("/player/");
|
||||
url += data + "/skin";
|
||||
HTTPRequest r(url);
|
||||
r.data = data;
|
||||
m_req_mutex.Lock();
|
||||
m_requests.push_back(r);
|
||||
m_req_mutex.Unlock();
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* /player/<name>/skin/hash/<sha1>
|
||||
* sends the sha1 hash of the skin texture for <name>
|
||||
* response:
|
||||
* if hash is the same on client and server:
|
||||
* 204 No Content
|
||||
* if client is authenticated as <name>:
|
||||
* 304 Not Modified
|
||||
* else:
|
||||
* 200 OK + texture data
|
||||
*/
|
||||
case HTTPREQUEST_SKIN_HASH:
|
||||
{
|
||||
std::string tex = std::string("player_") + data + ".png";
|
||||
std::string ptex = getPath("player",tex,true);
|
||||
if (ptex == "") {
|
||||
if (data == m_client->getLocalPlayer()->getName()) {
|
||||
ptex = getPath("texture","player.png",true);
|
||||
if (ptex == "")
|
||||
return;
|
||||
}else{
|
||||
pushRequest(HTTPREQUEST_SKIN,data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
char buff[100];
|
||||
SHA1 s;
|
||||
s.addFile(ptex.c_str());
|
||||
s.getDigest(buff);
|
||||
std::string url("/player/");
|
||||
url += data + "/skin/hash/" + buff;
|
||||
HTTPRequest r(url);
|
||||
r.data = data;
|
||||
m_req_mutex.Lock();
|
||||
m_requests.push_back(r);
|
||||
m_req_mutex.Unlock();
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* /player/<name>/skin
|
||||
* PUT request type, sends the skin to the server
|
||||
* response:
|
||||
* if client is authenticated as <name>:
|
||||
* 201 Created
|
||||
* else:
|
||||
* 405 Method Not Allowed
|
||||
*/
|
||||
case HTTPREQUEST_SKIN_SEND:
|
||||
{
|
||||
std::string tex = std::string("player.png");
|
||||
std::string ptex = getPath("texture",tex,true);
|
||||
if (ptex == "")
|
||||
return;
|
||||
|
||||
std::string url("/player/");
|
||||
url += data + "/skin";
|
||||
HTTPRequest r(url,ptex,data);
|
||||
m_req_mutex.Lock();
|
||||
m_requests.push_back(r);
|
||||
m_req_mutex.Unlock();
|
||||
break;
|
||||
}
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
@ -844,42 +612,6 @@ bool HTTPClient::get(std::string &url)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* send a http POST request to the server */
|
||||
bool HTTPClient::post(std::string &url, char* data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* send a file to the server with a http PUT request */
|
||||
bool HTTPClient::put(std::string &url, std::string &file)
|
||||
{
|
||||
FILE *f;
|
||||
u32 s;
|
||||
f = fopen(file.c_str(),"r");
|
||||
if (!f)
|
||||
return false;
|
||||
fseek(f,0,SEEK_END);
|
||||
s = ftell(f);
|
||||
fseek(f,0,SEEK_SET);
|
||||
m_send_headers.setLength(s);
|
||||
m_send_headers.setHeader("Content-Type","image/png");
|
||||
m_send_headers.setMethod("PUT");
|
||||
m_send_headers.setUrl(url);
|
||||
|
||||
sendHeaders();
|
||||
|
||||
u32 t = 0;
|
||||
u32 l;
|
||||
|
||||
char buff[1024];
|
||||
while ((l = fread(buff,1,1024,f)) > 0) {
|
||||
t += l;
|
||||
m_socket->Send(buff,l);
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* send http headers to the server */
|
||||
void HTTPClient::sendHeaders()
|
||||
{
|
||||
|
@ -900,9 +632,6 @@ void HTTPClient::sendHeaders()
|
|||
s = snprintf(buff,1024,"Content-Length: %d\r\n",s);
|
||||
m_socket->Send(buff,s);
|
||||
|
||||
s = snprintf(buff,1024,"Cookie: MTID=%s\r\n",m_cookie.c_str());
|
||||
m_socket->Send(buff,s);
|
||||
|
||||
s = snprintf(buff,1024,"User: %s\r\n",m_client->getLocalPlayer()->getName());
|
||||
m_socket->Send(buff,s);
|
||||
|
||||
|
@ -927,7 +656,6 @@ int HTTPRequestHeaders::read(TCPSocket *sock)
|
|||
return -1;
|
||||
n = lbuff;
|
||||
lbuff[i] = 0;
|
||||
printf("%s\n",n);
|
||||
{
|
||||
v = strchr(n,' ');
|
||||
if (!v)
|
||||
|
@ -969,8 +697,6 @@ printf("%s\n",n);
|
|||
}
|
||||
if (!strcmp(n,"Content-Length")) {
|
||||
setLength(strtoul(v,NULL,10));
|
||||
}else if (!strcmp(n,"Cookie") && !strncmp(v,"MTID=",5)) {
|
||||
setCookie(v+5);
|
||||
}else{
|
||||
setHeader(n,v);
|
||||
}
|
||||
|
@ -992,7 +718,6 @@ int HTTPResponseHeaders::read(TCPSocket *sock)
|
|||
return -1;
|
||||
n = lbuff;
|
||||
lbuff[i] = 0;
|
||||
printf("%s\n",n);
|
||||
{
|
||||
v = strchr(n,' ');
|
||||
if (!v)
|
||||
|
@ -1022,8 +747,6 @@ printf("%s\n",n);
|
|||
}
|
||||
if (!strcmp(n,"Content-Length")) {
|
||||
setLength(strtoul(v,NULL,10));
|
||||
}else if (!strcmp(n,"SetCookie") && !strncmp(v,"MTID=",5)) {
|
||||
setCookie(v+5);
|
||||
}else{
|
||||
setHeader(n,v);
|
||||
}
|
||||
|
|
18
src/http.h
18
src/http.h
|
@ -58,20 +58,17 @@ public:
|
|||
void clear()
|
||||
{
|
||||
m_contentLength = 0;
|
||||
m_cookie = std::string("");
|
||||
m_url = std::string("");
|
||||
m_url_split.clear();
|
||||
}
|
||||
virtual int read(TCPSocket *sock) = 0;
|
||||
u32 length() {return m_contentLength;}
|
||||
std::string getCookie() {return m_cookie;}
|
||||
std::string getUrl() {return m_url;}
|
||||
std::string getUrl(unsigned int index) { if (m_url_split.size() > index) return m_url_split[index]; return std::string("");}
|
||||
std::string getHeader(std::string name) {return m_headers[name];}
|
||||
std::string getMethod() {return m_method;}
|
||||
u32 getLength() {return m_contentLength;}
|
||||
|
||||
void setCookie(std::string cookie) {std::string c(cookie.c_str()); m_cookie = c;}
|
||||
void setUrl(std::string url) {std::string u(url); m_url = u;}
|
||||
void addUrl(std::string url) {m_url_split.push_back(url);}
|
||||
void setHeader(std::string name, std::string value) {m_headers[name] = value;}
|
||||
|
@ -80,7 +77,6 @@ public:
|
|||
private:
|
||||
std::map<std::string,std::string> m_headers;
|
||||
u32 m_contentLength;
|
||||
std::string m_cookie;
|
||||
std::string m_url;
|
||||
std::vector<std::string> m_url_split;
|
||||
std::string m_method;
|
||||
|
@ -120,9 +116,8 @@ private:
|
|||
int readline(char* buff, int size) {return m_socket->ReceiveLine(buff,size);}
|
||||
void sendHeaders();
|
||||
|
||||
int handlePlayer();
|
||||
int handleTexture();
|
||||
int handleModel();
|
||||
int handlePlayer();
|
||||
int handleMap();
|
||||
int handleIndex();
|
||||
int handleSpecial(const char* response, std::string content);
|
||||
|
@ -151,8 +146,6 @@ public:
|
|||
void start(u16 port);
|
||||
void stop();
|
||||
void step();
|
||||
std::string getPlayerCookie(std::string name) {return m_server->getPlayerCookie(name);}
|
||||
std::string getPlayerFromCookie(std::string cookie) {return m_server->getPlayerFromCookie(cookie);}
|
||||
std::string getPlayerPrivs(std::string name) {return privsToString(m_server->getPlayerAuthPrivs(name));}
|
||||
Server *getGameServer() {return m_server;}
|
||||
private:
|
||||
|
@ -163,10 +156,7 @@ private:
|
|||
};
|
||||
|
||||
enum HTTPRequestType {
|
||||
HTTPREQUEST_NULL,
|
||||
HTTPREQUEST_SKIN,
|
||||
HTTPREQUEST_SKIN_HASH,
|
||||
HTTPREQUEST_SKIN_SEND
|
||||
HTTPREQUEST_NULL
|
||||
};
|
||||
|
||||
struct HTTPRequest
|
||||
|
@ -227,13 +217,10 @@ public:
|
|||
void start(const Address &address);
|
||||
void stop();
|
||||
void step();
|
||||
void setCookie(std::string &cookie) {std::string c(cookie.c_str()); m_cookie = c;}
|
||||
void pushRequest(HTTPRequestType type, std::string &data);
|
||||
void pushRequest(std::string &url, std::string &data);
|
||||
private:
|
||||
bool get(std::string &url);
|
||||
bool post(std::string &url, char* data);
|
||||
bool put(std::string &url, std::string &file);
|
||||
int read(char* buff, int size) {return m_socket->Receive(buff,size);}
|
||||
int readline(char* buff, int size) {return m_socket->ReceiveLine(buff,size);}
|
||||
void sendHeaders();
|
||||
|
@ -242,7 +229,6 @@ private:
|
|||
TCPSocket *m_socket;
|
||||
HTTPResponseHeaders m_recv_headers;
|
||||
HTTPRequestHeaders m_send_headers;
|
||||
std::string m_cookie;
|
||||
std::vector<HTTPRequest> m_requests;
|
||||
JMutex m_req_mutex;
|
||||
HTTPClientThread m_thread;
|
||||
|
|
15
src/player.h
15
src/player.h
|
@ -146,7 +146,6 @@ public:
|
|||
{
|
||||
light = light_at_pos;
|
||||
}
|
||||
virtual std::string getCookie() {return "";}
|
||||
|
||||
virtual void updateAnim(u8 anim_id)
|
||||
{}
|
||||
|
@ -284,8 +283,7 @@ class ServerRemotePlayer : public Player
|
|||
{
|
||||
public:
|
||||
ServerRemotePlayer():
|
||||
m_addr(""),
|
||||
m_cookie("")
|
||||
m_addr("")
|
||||
{
|
||||
}
|
||||
virtual ~ServerRemotePlayer()
|
||||
|
@ -307,18 +305,7 @@ public:
|
|||
virtual void setCharDef(std::string d);
|
||||
|
||||
private:
|
||||
virtual std::string getCookie()
|
||||
{
|
||||
if (m_cookie == "") {
|
||||
char buff[256];
|
||||
snprintf(buff,256,"%s%.4X",getName(),peer_id);
|
||||
m_cookie = std::string(buff);
|
||||
}
|
||||
return m_cookie;
|
||||
}
|
||||
|
||||
std::string m_addr;
|
||||
std::string m_cookie;
|
||||
};
|
||||
|
||||
#ifndef SERVER
|
||||
|
|
|
@ -4930,11 +4930,6 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
<<PP(player->getPosition()/BS)<<std::endl;
|
||||
}
|
||||
break;
|
||||
case TOSERVER_WANTCOOKIE:
|
||||
{
|
||||
SendPlayerCookie(player);
|
||||
}
|
||||
break;
|
||||
case TOSERVER_NODEMETA_FIELDS:
|
||||
{
|
||||
std::string datastring((char*)&data[2], datasize-2);
|
||||
|
@ -5469,22 +5464,6 @@ void Server::SendPlayerHP(Player *player)
|
|||
SendHP(m_con, player->peer_id, hp,air,hunger);
|
||||
}
|
||||
|
||||
void Server::SendPlayerCookie(Player *player)
|
||||
{
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
std::string c = player->getCookie();
|
||||
|
||||
writeU16(os, TOCLIENT_HAVECOOKIE);
|
||||
writeU16(os, c.size());
|
||||
os.write(c.c_str(),c.size());
|
||||
|
||||
// Make data buffer
|
||||
std::string s = os.str();
|
||||
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
|
||||
// Send as reliable
|
||||
m_con.Send(player->peer_id, 0, data, true);
|
||||
}
|
||||
|
||||
void Server::SendSettings(Player *player)
|
||||
{
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
|
|
18
src/server.h
18
src/server.h
|
@ -457,23 +457,6 @@ public:
|
|||
}
|
||||
void setPlayerPassword(const char *name, const char *password) {m_authmanager.setPassword(name,password);}
|
||||
|
||||
std::string getPlayerCookie(std::string &name)
|
||||
{
|
||||
Player *p = m_env.getPlayer(name.c_str());
|
||||
if (p == NULL)
|
||||
return "";
|
||||
return p->getCookie();
|
||||
}
|
||||
std::string getPlayerFromCookie(std::string &cookie)
|
||||
{
|
||||
core::list<Player*> players = m_env.getPlayers();
|
||||
for (core::list<Player*>::Iterator i = players.begin(); i != players.end(); i++) {
|
||||
Player *player = *i;
|
||||
if (player->getCookie() == cookie)
|
||||
return player->getName();
|
||||
}
|
||||
return std::string("");
|
||||
}
|
||||
Player *getPlayer(std::string name) {return m_env.getPlayer(name.c_str());}
|
||||
core::list<Player*> getPlayers() {return m_env.getPlayers();}
|
||||
core::list<Player*> getPlayers(bool ign_disconnected) {return m_env.getPlayers(ign_disconnected);}
|
||||
|
@ -543,7 +526,6 @@ private:
|
|||
void SendChatMessage(u16 peer_id, const std::wstring &message);
|
||||
void BroadcastChatMessage(const std::wstring &message);
|
||||
void SendPlayerHP(Player *player);
|
||||
void SendPlayerCookie(Player *player);
|
||||
// tell the client what kind of game is being played
|
||||
void SendSettings(Player *player);
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue