it works, mostly

This commit is contained in:
darkrose 2013-12-01 03:16:51 +10:00
parent be72505add
commit 39d21ecf32
3 changed files with 12 additions and 15 deletions

View File

@ -158,7 +158,7 @@
#time_send_interval = 20
# Length of day/night cycle. 72=20min, 360=4min, 1=24hour
#time_speed = 72
# enable a http microserver for admin and player textures
# enable a http microserver player texture transfers
#enable_http = true
#server_unload_unused_data_timeout = 60
#server_map_save_interval = 60

View File

@ -331,6 +331,7 @@ int HTTPRemoteClient::handlePlayer()
}
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");
@ -346,16 +347,13 @@ int HTTPRemoteClient::handlePlayer()
size_t t = 0;
if (c > s)
c = s;
printf("pending: %lu %lu %d %d\n",c,s,m_start,m_end);
if (c) {
printf("pending: %lu %lu %d %d\n",c,s,m_start,m_end);
if (m_start == m_end)
m_socket->WaitData(5000);
m_socket->WaitData(60000);
while ((l = read(buff,c)) > 0) {
s -= l;
t += l;
c = fwrite(buff,1,l,f);
printf("written: %lu\n",c);
if (c != l) {
fclose(f);
return handleSpecial("500 Internal Server Error");
@ -367,10 +365,9 @@ printf("written: %lu\n",c);
break;
}
}
printf("received: %lu %lu\n",s,t);
l = ftell(f);
fclose(f);
if (s == t)
if (l == t)
return handleSpecial("201 Created");
fs::RecursiveDelete(file.c_str());
return handleSpecial("500 Internal Server Error");
@ -784,19 +781,19 @@ void HTTPClient::step()
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 s = m_recv_headers.getLength();
if (!s) {
delete m_socket;
fclose(f);
continue;
}
size_t l;
size_t c = 2048;
if (c > s)
@ -972,7 +969,6 @@ bool HTTPClient::put(std::string &url, std::string &file)
t += l;
m_socket->Send(buff,l);
}
printf("sent: %u %u\n",t,s);
fclose(f);
return true;
}
@ -1150,7 +1146,6 @@ int HTTPResponseHeaders::read(char* buff, int length)
if (buff[i] == '\n') {
if (!c) {
nbuff[o] = 0;
printf("%d '%s'\n",__LINE__,nbuff);
char* r = strchr(nbuff,' ');
if (!r)
return -1;

View File

@ -129,6 +129,8 @@ std::string getPath(const char* tp, const std::string &filename, bool must_exist
rel_path += std::string("html")+DIR_DELIM+filename;
}else if (type == "player") {
rel_path += std::string("textures")+DIR_DELIM+"players"+DIR_DELIM+filename;
}else{
rel_path += filename;
}
/* check from data_path */