Update code style to C++11

master
Elias Fleckenstein 2021-05-15 21:32:06 +02:00
parent b41a2e9ba2
commit 107081988e
6 changed files with 154 additions and 156 deletions

View File

@ -67,7 +67,7 @@ public:
MeshUpdateQueue(); MeshUpdateQueue();
~MeshUpdateQueue(); ~MeshUpdateQueue();
/* /*
peer_id=0 adds with nobody to send to peer_id=0 adds with nobody to send to
*/ */
@ -82,7 +82,7 @@ public:
JMutexAutoLock lock(m_mutex); JMutexAutoLock lock(m_mutex);
return m_queue.size(); return m_queue.size();
} }
private: private:
core::list<QueuedMeshUpdate*> m_queue; core::list<QueuedMeshUpdate*> m_queue;
JMutex m_mutex; JMutex m_mutex;
@ -169,7 +169,7 @@ public:
IWritableItemDefManager *itemdef, IWritableItemDefManager *itemdef,
IWritableNodeDefManager *nodedef IWritableNodeDefManager *nodedef
); );
~Client(); ~Client();
/* /*
The name of the local player should already be set when The name of the local player should already be set when
@ -214,16 +214,16 @@ public:
const std::wstring newpassword); const std::wstring newpassword);
void sendDamage(u8 damage); void sendDamage(u8 damage);
void sendRespawn(); void sendRespawn();
// locks envlock // locks envlock
void removeNode(v3s16 p); void removeNode(v3s16 p);
// locks envlock // locks envlock
void addNode(v3s16 p, MapNode n); void addNode(v3s16 p, MapNode n);
void updateCamera(v3f pos, v3f dir, f32 fov); void updateCamera(v3f pos, v3f dir, f32 fov);
void renderPostFx(); void renderPostFx();
// Returns InvalidPositionException if not found // Returns InvalidPositionException if not found
MapNode getNode(v3s16 p); MapNode getNode(v3s16 p);
// Wrapper to Map // Wrapper to Map
@ -242,7 +242,7 @@ public:
bool getLocalInventoryUpdated(); bool getLocalInventoryUpdated();
// Copies the inventory of the local player to parameter // Copies the inventory of the local player to parameter
void getLocalInventory(Inventory &dst); void getLocalInventory(Inventory &dst);
/* InventoryManager interface */ /* InventoryManager interface */
Inventory* getInventory(const InventoryLocation &loc); Inventory* getInventory(const InventoryLocation &loc);
void inventoryAction(InventoryAction *a); void inventoryAction(InventoryAction *a);
@ -269,7 +269,7 @@ public:
{ {
try{ try{
return m_con.GetPeerAvgRTT(PEER_ID_SERVER); return m_con.GetPeerAvgRTT(PEER_ID_SERVER);
} catch(con::PeerNotFoundException){ } catch(con::PeerNotFoundException &){
return 1337; return 1337;
} }
} }
@ -306,7 +306,7 @@ public:
// Get event from queue. CE_NONE is returned if queue is empty. // Get event from queue. CE_NONE is returned if queue is empty.
ClientEvent getClientEvent(); ClientEvent getClientEvent();
bool accessDenied() bool accessDenied()
{ return m_access_denied; } { return m_access_denied; }
@ -322,7 +322,7 @@ public:
{ return m_itemdef_received; } { return m_itemdef_received; }
bool nodedefReceived() bool nodedefReceived()
{ return m_nodedef_received; } { return m_nodedef_received; }
void afterContentReceived(); void afterContentReceived();
float getRTT(void); float getRTT(void);
@ -335,20 +335,20 @@ public:
virtual u16 allocateUnknownNodeId(const std::string &name); virtual u16 allocateUnknownNodeId(const std::string &name);
private: private:
// Virtual methods from con::PeerHandler // Virtual methods from con::PeerHandler
void peerAdded(con::Peer *peer); void peerAdded(con::Peer *peer);
void deletingPeer(con::Peer *peer, bool timeout); void deletingPeer(con::Peer *peer, bool timeout);
void ReceiveAll(); void ReceiveAll();
void Receive(); void Receive();
void sendPlayerPos(); void sendPlayerPos();
// This sends the player's current name etc to the server // This sends the player's current name etc to the server
void sendPlayerInfo(); void sendPlayerInfo();
// Send the item number 'item' as player item to the server // Send the item number 'item' as player item to the server
void sendPlayerItem(u16 item); void sendPlayerItem(u16 item);
float m_packetcounter_timer; float m_packetcounter_timer;
float m_connection_reinit_timer; float m_connection_reinit_timer;
float m_avg_rtt_timer; float m_avg_rtt_timer;

View File

@ -70,7 +70,7 @@ core::list<SharedBuffer<u8> > makeSplitPacket(
{ {
// Chunk packets, containing the TYPE_SPLIT header // Chunk packets, containing the TYPE_SPLIT header
core::list<SharedBuffer<u8> > chunks; core::list<SharedBuffer<u8> > chunks;
u32 chunk_header_size = 7; u32 chunk_header_size = 7;
u32 maximum_data_size = chunksize_max - chunk_header_size; u32 maximum_data_size = chunksize_max - chunk_header_size;
u32 start = 0; u32 start = 0;
@ -80,12 +80,12 @@ core::list<SharedBuffer<u8> > makeSplitPacket(
end = start + maximum_data_size - 1; end = start + maximum_data_size - 1;
if(end > data.getSize() - 1) if(end > data.getSize() - 1)
end = data.getSize() - 1; end = data.getSize() - 1;
u32 payload_size = end - start + 1; u32 payload_size = end - start + 1;
u32 packet_size = chunk_header_size + payload_size; u32 packet_size = chunk_header_size + payload_size;
SharedBuffer<u8> chunk(packet_size); SharedBuffer<u8> chunk(packet_size);
writeU8(&chunk[0], TYPE_SPLIT); writeU8(&chunk[0], TYPE_SPLIT);
writeU16(&chunk[1], seqnum); writeU16(&chunk[1], seqnum);
// [3] u16 chunk_count is written at next stage // [3] u16 chunk_count is written at next stage
@ -93,7 +93,7 @@ core::list<SharedBuffer<u8> > makeSplitPacket(
memcpy(&chunk[chunk_header_size], &data[start], payload_size); memcpy(&chunk[chunk_header_size], &data[start], payload_size);
chunks.push_back(chunk); chunks.push_back(chunk);
start = end + 1; start = end + 1;
chunk_num++; chunk_num++;
} }
@ -340,9 +340,9 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
sp->reliable = reliable; sp->reliable = reliable;
m_buf[seqnum] = sp; m_buf[seqnum] = sp;
} }
IncomingSplitPacket *sp = m_buf[seqnum]; IncomingSplitPacket *sp = m_buf[seqnum];
// TODO: These errors should be thrown or something? Dunno. // TODO: These errors should be thrown or something? Dunno.
if(chunk_count != sp->chunk_count) if(chunk_count != sp->chunk_count)
derr_con<<"Connection: WARNING: chunk_count="<<chunk_count derr_con<<"Connection: WARNING: chunk_count="<<chunk_count
@ -356,15 +356,15 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
// If chunk already exists, cancel // If chunk already exists, cancel
if(sp->chunks.find(chunk_num) != NULL) if(sp->chunks.find(chunk_num) != NULL)
throw AlreadyExistsException("Chunk already in buffer"); throw AlreadyExistsException("Chunk already in buffer");
// Cut chunk data out of packet // Cut chunk data out of packet
u32 chunkdatasize = p.data.getSize() - headersize; u32 chunkdatasize = p.data.getSize() - headersize;
SharedBuffer<u8> chunkdata(chunkdatasize); SharedBuffer<u8> chunkdata(chunkdatasize);
memcpy(*chunkdata, &(p.data[headersize]), chunkdatasize); memcpy(*chunkdata, &(p.data[headersize]), chunkdatasize);
// Set chunk data in buffer // Set chunk data in buffer
sp->chunks[chunk_num] = chunkdata; sp->chunks[chunk_num] = chunkdata;
// If not all chunks are received, return empty buffer // If not all chunks are received, return empty buffer
if(sp->allReceived() == false) if(sp->allReceived() == false)
return SharedBuffer<u8>(); return SharedBuffer<u8>();
@ -377,7 +377,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
{ {
totalsize += i.getNode()->getValue().getSize(); totalsize += i.getNode()->getValue().getSize();
} }
SharedBuffer<u8> fulldata(totalsize); SharedBuffer<u8> fulldata(totalsize);
// Copy chunks to data buffer // Copy chunks to data buffer
@ -481,7 +481,7 @@ void Peer::reportRTT(float rtt)
avg_rtt = rtt; avg_rtt = rtt;
else else
avg_rtt = rtt * 0.1 + avg_rtt * 0.9; avg_rtt = rtt * 0.1 + avg_rtt * 0.9;
// Calculate resend_timeout // Calculate resend_timeout
/*int reliable_count = 0; /*int reliable_count = 0;
@ -491,7 +491,7 @@ void Peer::reportRTT(float rtt)
} }
float timeout = avg_rtt * RESEND_TIMEOUT_FACTOR float timeout = avg_rtt * RESEND_TIMEOUT_FACTOR
* ((float)reliable_count * 1);*/ * ((float)reliable_count * 1);*/
float timeout = avg_rtt * RESEND_TIMEOUT_FACTOR; float timeout = avg_rtt * RESEND_TIMEOUT_FACTOR;
if(timeout < RESEND_TIMEOUT_MIN) if(timeout < RESEND_TIMEOUT_MIN)
timeout = RESEND_TIMEOUT_MIN; timeout = RESEND_TIMEOUT_MIN;
@ -499,7 +499,7 @@ void Peer::reportRTT(float rtt)
timeout = RESEND_TIMEOUT_MAX; timeout = RESEND_TIMEOUT_MAX;
resend_timeout = timeout; resend_timeout = timeout;
} }
/* /*
Connection Connection
*/ */
@ -547,14 +547,14 @@ void * Connection::Thread()
log_register_thread("Connection"); log_register_thread("Connection");
dout_con<<"Connection thread started"<<std::endl; dout_con<<"Connection thread started"<<std::endl;
u32 curtime = porting::getTimeMs(); u32 curtime = porting::getTimeMs();
u32 lasttime = curtime; u32 lasttime = curtime;
while(getRun()) while(getRun())
{ {
BEGIN_DEBUG_EXCEPTION_HANDLER BEGIN_DEBUG_EXCEPTION_HANDLER
lasttime = curtime; lasttime = curtime;
curtime = porting::getTimeMs(); curtime = porting::getTimeMs();
float dtime = (float)(curtime - lasttime) / 1000.; float dtime = (float)(curtime - lasttime) / 1000.;
@ -562,7 +562,7 @@ void * Connection::Thread()
dtime = 0.1; dtime = 0.1;
if(dtime < 0.0) if(dtime < 0.0)
dtime = 0.0; dtime = 0.0;
runTimeouts(dtime); runTimeouts(dtime);
while(m_command_queue.size() != 0){ while(m_command_queue.size() != 0){
@ -573,7 +573,7 @@ void * Connection::Thread()
send(dtime); send(dtime);
receive(); receive();
END_DEBUG_EXCEPTION_HANDLER(derr_con); END_DEBUG_EXCEPTION_HANDLER(derr_con);
} }
@ -673,7 +673,7 @@ void Connection::receive()
SharedBuffer<u8> packetdata(packet_maxsize); SharedBuffer<u8> packetdata(packet_maxsize);
bool single_wait_done = false; bool single_wait_done = false;
for(;;) for(;;)
{ {
try{ try{
@ -689,12 +689,12 @@ void Connection::receive()
continue; continue;
} }
} }
if(single_wait_done){ if(single_wait_done){
if(m_socket.WaitData(0) == false) if(m_socket.WaitData(0) == false)
break; break;
} }
single_wait_done = true; single_wait_done = true;
Address sender; Address sender;
@ -706,7 +706,7 @@ void Connection::receive()
continue; continue;
if(readU32(&packetdata[0]) != m_protocol_id) if(readU32(&packetdata[0]) != m_protocol_id)
continue; continue;
u16 peer_id = readPeerId(*packetdata); u16 peer_id = readPeerId(*packetdata);
u8 channelnum = readChannel(*packetdata); u8 channelnum = readChannel(*packetdata);
if(channelnum > CHANNEL_COUNT-1){ if(channelnum > CHANNEL_COUNT-1){
@ -719,7 +719,7 @@ void Connection::receive()
{ {
/* /*
Somebody is trying to send stuff to us with no peer id. Somebody is trying to send stuff to us with no peer id.
Check if the same address and port was added to our peer Check if the same address and port was added to our peer
list before. list before.
Allow only entries that have has_sent_with_id==false. Allow only entries that have has_sent_with_id==false.
@ -735,7 +735,7 @@ void Connection::receive()
if(peer->address == sender) if(peer->address == sender)
break; break;
} }
/* /*
If no peer was found with the same address and port, If no peer was found with the same address and port,
we shall assume it is a new peer and create an entry. we shall assume it is a new peer and create an entry.
@ -754,7 +754,7 @@ void Connection::receive()
<<"peer_id="<<peer_id<<std::endl; <<"peer_id="<<peer_id<<std::endl;
} }
} }
/* /*
The peer was not found in our lists. Add it. The peer was not found in our lists. Add it.
*/ */
@ -792,19 +792,19 @@ void Connection::receive()
// Create a peer // Create a peer
Peer *peer = new Peer(peer_id_new, sender); Peer *peer = new Peer(peer_id_new, sender);
m_peers.insert(peer->id, peer); m_peers.insert(peer->id, peer);
// Create peer addition event // Create peer addition event
ConnectionEvent e; ConnectionEvent e;
e.peerAdded(peer_id_new, sender); e.peerAdded(peer_id_new, sender);
putEvent(e); putEvent(e);
// Create CONTROL packet to tell the peer id to the new peer. // Create CONTROL packet to tell the peer id to the new peer.
SharedBuffer<u8> reply(4); SharedBuffer<u8> reply(4);
writeU8(&reply[0], TYPE_CONTROL); writeU8(&reply[0], TYPE_CONTROL);
writeU8(&reply[1], CONTROLTYPE_SET_PEER_ID); writeU8(&reply[1], CONTROLTYPE_SET_PEER_ID);
writeU16(&reply[2], peer_id_new); writeU16(&reply[2], peer_id_new);
sendAsPacket(peer_id_new, 0, reply, true); sendAsPacket(peer_id_new, 0, reply, true);
// We're now talking to a valid peer_id // We're now talking to a valid peer_id
peer_id = peer_id_new; peer_id = peer_id_new;
@ -833,27 +833,27 @@ void Connection::receive()
" Ignoring."<<std::endl; " Ignoring."<<std::endl;
continue; continue;
} }
peer->timeout_counter = 0.0; peer->timeout_counter = 0.0;
Channel *channel = &(peer->channels[channelnum]); Channel *channel = &(peer->channels[channelnum]);
// Throw the received packet to channel->processPacket() // Throw the received packet to channel->processPacket()
// Make a new SharedBuffer from the data without the base headers // Make a new SharedBuffer from the data without the base headers
SharedBuffer<u8> strippeddata(received_size - BASE_HEADER_SIZE); SharedBuffer<u8> strippeddata(received_size - BASE_HEADER_SIZE);
memcpy(*strippeddata, &packetdata[BASE_HEADER_SIZE], memcpy(*strippeddata, &packetdata[BASE_HEADER_SIZE],
strippeddata.getSize()); strippeddata.getSize());
try{ try{
// Process it (the result is some data with no headers made by us) // Process it (the result is some data with no headers made by us)
SharedBuffer<u8> resultdata = processPacket SharedBuffer<u8> resultdata = processPacket
(channel, strippeddata, peer_id, channelnum, false); (channel, strippeddata, peer_id, channelnum, false);
PrintInfo(); PrintInfo();
dout_con<<"ProcessPacket returned data of size " dout_con<<"ProcessPacket returned data of size "
<<resultdata.getSize()<<std::endl; <<resultdata.getSize()<<std::endl;
ConnectionEvent e; ConnectionEvent e;
e.dataReceived(peer_id, resultdata); e.dataReceived(peer_id, resultdata);
putEvent(e); putEvent(e);
@ -875,7 +875,7 @@ void Connection::runTimeouts(float dtime)
for(; j.atEnd() == false; j++) for(; j.atEnd() == false; j++)
{ {
Peer *peer = j.getNode()->getValue(); Peer *peer = j.getNode()->getValue();
/* /*
Check peer timeout Check peer timeout
*/ */
@ -898,12 +898,12 @@ void Connection::runTimeouts(float dtime)
{ {
core::list<BufferedPacket> timed_outs; core::list<BufferedPacket> timed_outs;
core::list<BufferedPacket>::Iterator j; core::list<BufferedPacket>::Iterator j;
Channel *channel = &peer->channels[i]; Channel *channel = &peer->channels[i];
// Remove timed out incomplete unreliable split packets // Remove timed out incomplete unreliable split packets
channel->incoming_splits.removeUnreliableTimedOuts(dtime, m_timeout); channel->incoming_splits.removeUnreliableTimedOuts(dtime, m_timeout);
// Increment reliable packet times // Increment reliable packet times
channel->outgoing_reliables.incrementTimeouts(dtime); channel->outgoing_reliables.incrementTimeouts(dtime);
@ -922,7 +922,7 @@ void Connection::runTimeouts(float dtime)
} }
// Re-send timed out outgoing reliables // Re-send timed out outgoing reliables
timed_outs = channel-> timed_outs = channel->
outgoing_reliables.getTimedOuts(resend_timeout); outgoing_reliables.getTimedOuts(resend_timeout);
@ -953,7 +953,7 @@ void Connection::runTimeouts(float dtime)
peer->reportRTT(resend_timeout); peer->reportRTT(resend_timeout);
} }
} }
/* /*
Send pings Send pings
*/ */
@ -968,7 +968,7 @@ void Connection::runTimeouts(float dtime)
peer->ping_timer = 0.0; peer->ping_timer = 0.0;
} }
nextpeer: nextpeer:
continue; continue;
} }
@ -1007,9 +1007,9 @@ void Connection::connect(Address address)
ConnectionEvent e; ConnectionEvent e;
e.peerAdded(peer->id, peer->address); e.peerAdded(peer->id, peer->address);
putEvent(e); putEvent(e);
m_socket.Bind(0); m_socket.Bind(0);
// Send a dummy packet to server with peer_id = PEER_ID_INEXISTENT // Send a dummy packet to server with peer_id = PEER_ID_INEXISTENT
m_peer_id = PEER_ID_INEXISTENT; m_peer_id = PEER_ID_INEXISTENT;
SharedBuffer<u8> data(0); SharedBuffer<u8> data(0);
@ -1024,7 +1024,7 @@ void Connection::disconnect()
SharedBuffer<u8> data(2); SharedBuffer<u8> data(2);
writeU8(&data[0], TYPE_CONTROL); writeU8(&data[0], TYPE_CONTROL);
writeU8(&data[1], CONTROLTYPE_DISCO); writeU8(&data[1], CONTROLTYPE_DISCO);
// Send to all // Send to all
core::map<u16, Peer*>::Iterator j; core::map<u16, Peer*>::Iterator j;
j = m_peers.getIterator(); j = m_peers.getIterator();
@ -1052,7 +1052,7 @@ void Connection::send(u16 peer_id, u8 channelnum,
dout_con<<getDesc()<<" sending to peer_id="<<peer_id<<std::endl; dout_con<<getDesc()<<" sending to peer_id="<<peer_id<<std::endl;
assert(channelnum < CHANNEL_COUNT); assert(channelnum < CHANNEL_COUNT);
Peer *peer = getPeerNoEx(peer_id); Peer *peer = getPeerNoEx(peer_id);
if(peer == NULL) if(peer == NULL)
return; return;
@ -1065,13 +1065,13 @@ void Connection::send(u16 peer_id, u8 channelnum,
core::list<SharedBuffer<u8> > originals; core::list<SharedBuffer<u8> > originals;
originals = makeAutoSplitPacket(data, chunksize_max, originals = makeAutoSplitPacket(data, chunksize_max,
channel->next_outgoing_split_seqnum); channel->next_outgoing_split_seqnum);
core::list<SharedBuffer<u8> >::Iterator i; core::list<SharedBuffer<u8> >::Iterator i;
i = originals.begin(); i = originals.begin();
for(; i != originals.end(); i++) for(; i != originals.end(); i++)
{ {
SharedBuffer<u8> original = *i; SharedBuffer<u8> original = *i;
sendAsPacket(peer_id, channelnum, original, reliable); sendAsPacket(peer_id, channelnum, original, reliable);
} }
} }
@ -1101,7 +1101,7 @@ void Connection::rawSendAsPacket(u16 peer_id, u8 channelnum,
// Add base headers and make a packet // Add base headers and make a packet
BufferedPacket p = makePacket(peer->address, reliable, BufferedPacket p = makePacket(peer->address, reliable,
m_protocol_id, m_peer_id, channelnum); m_protocol_id, m_peer_id, channelnum);
try{ try{
// Buffer the packet // Buffer the packet
channel->outgoing_reliables.insert(p); channel->outgoing_reliables.insert(p);
@ -1114,7 +1114,7 @@ void Connection::rawSendAsPacket(u16 peer_id, u8 channelnum,
"in outgoing buffer"<<std::endl; "in outgoing buffer"<<std::endl;
//assert(0); //assert(0);
} }
// Send the packet // Send the packet
rawSend(p); rawSend(p);
} }
@ -1215,15 +1215,15 @@ bool Connection::checkIncomingBuffers(Channel *channel, u16 &peer_id,
break; break;
} }
// This happens if all packets are old // This happens if all packets are old
}catch(con::NotFoundException) }catch(con::NotFoundException &)
{} {}
if(channel->incoming_reliables.empty() == false) if(channel->incoming_reliables.empty() == false)
{ {
if(firstseqnum == channel->next_incoming_seqnum) if(firstseqnum == channel->next_incoming_seqnum)
{ {
BufferedPacket p = channel->incoming_reliables.popFirst(); BufferedPacket p = channel->incoming_reliables.popFirst();
peer_id = readPeerId(*p.data); peer_id = readPeerId(*p.data);
u8 channelnum = readChannel(*p.data); u8 channelnum = readChannel(*p.data);
u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]); u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]);
@ -1236,7 +1236,7 @@ bool Connection::checkIncomingBuffers(Channel *channel, u16 &peer_id,
<<std::endl; <<std::endl;
channel->next_incoming_seqnum++; channel->next_incoming_seqnum++;
u32 headers_size = BASE_HEADER_SIZE + RELIABLE_HEADER_SIZE; u32 headers_size = BASE_HEADER_SIZE + RELIABLE_HEADER_SIZE;
// Get out the inside packet and re-process it // Get out the inside packet and re-process it
SharedBuffer<u8> payload(p.data.getSize() - headers_size); SharedBuffer<u8> payload(p.data.getSize() - headers_size);
@ -1259,7 +1259,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
throw InvalidIncomingDataException("packetdata.getSize() < 1"); throw InvalidIncomingDataException("packetdata.getSize() < 1");
u8 type = readU8(&packetdata[0]); u8 type = readU8(&packetdata[0]);
if(type == TYPE_CONTROL) if(type == TYPE_CONTROL)
{ {
if(packetdata.getSize() < 2) if(packetdata.getSize() < 2)
@ -1342,7 +1342,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
// the timeout counter // the timeout counter
PrintInfo(); PrintInfo();
dout_con<<"DISCO: Removing peer "<<(peer_id)<<std::endl; dout_con<<"DISCO: Removing peer "<<(peer_id)<<std::endl;
if(deletePeer(peer_id, false) == false) if(deletePeer(peer_id, false) == false)
{ {
PrintInfo(derr_con); PrintInfo(derr_con);
@ -1407,7 +1407,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
bool is_future_packet = seqnum_higher(seqnum, channel->next_incoming_seqnum); bool is_future_packet = seqnum_higher(seqnum, channel->next_incoming_seqnum);
bool is_old_packet = seqnum_higher(channel->next_incoming_seqnum, seqnum); bool is_old_packet = seqnum_higher(channel->next_incoming_seqnum, seqnum);
PrintInfo(); PrintInfo();
if(is_future_packet) if(is_future_packet)
dout_con<<"BUFFERING"; dout_con<<"BUFFERING";
@ -1420,7 +1420,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
dout_con<<" [sending CONTROLTYPE_ACK" dout_con<<" [sending CONTROLTYPE_ACK"
" to peer_id="<<peer_id<<"]"; " to peer_id="<<peer_id<<"]";
dout_con<<std::endl; dout_con<<std::endl;
//DEBUG //DEBUG
//assert(channel->incoming_reliables.size() < 100); //assert(channel->incoming_reliables.size() < 100);
@ -1437,7 +1437,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
/*PrintInfo(); /*PrintInfo();
dout_con<<"Buffering reliable packet (seqnum=" dout_con<<"Buffering reliable packet (seqnum="
<<seqnum<<")"<<std::endl;*/ <<seqnum<<")"<<std::endl;*/
// This one comes later, buffer it. // This one comes later, buffer it.
// Actually we have to make a packet to buffer one. // Actually we have to make a packet to buffer one.
// Well, we have all the ingredients, so just do it. // Well, we have all the ingredients, so just do it.
@ -1449,7 +1449,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
channelnum); channelnum);
try{ try{
channel->incoming_reliables.insert(packet); channel->incoming_reliables.insert(packet);
/*PrintInfo(); /*PrintInfo();
dout_con<<"INCOMING: "; dout_con<<"INCOMING: ";
channel->incoming_reliables.print(); channel->incoming_reliables.print();
@ -1482,7 +1482,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
derr_con<<"Got invalid type="<<((int)type&0xff)<<std::endl; derr_con<<"Got invalid type="<<((int)type&0xff)<<std::endl;
throw InvalidIncomingDataException("Invalid packet type"); throw InvalidIncomingDataException("Invalid packet type");
} }
// We should never get here. // We should never get here.
// If you get here, add an exception or a return to some of the // If you get here, add an exception or a return to some of the
// above conditionals. // above conditionals.
@ -1494,7 +1494,7 @@ bool Connection::deletePeer(u16 peer_id, bool timeout)
{ {
if(m_peers.find(peer_id) == NULL) if(m_peers.find(peer_id) == NULL)
return false; return false;
Peer *peer = m_peers[peer_id]; Peer *peer = m_peers[peer_id];
// Create event // Create event
@ -1555,14 +1555,14 @@ bool Connection::Connected()
if(m_peers.size() != 1) if(m_peers.size() != 1)
return false; return false;
core::map<u16, Peer*>::Node *node = m_peers.find(PEER_ID_SERVER); core::map<u16, Peer*>::Node *node = m_peers.find(PEER_ID_SERVER);
if(node == NULL) if(node == NULL)
return false; return false;
if(m_peer_id == PEER_ID_INEXISTENT) if(m_peer_id == PEER_ID_INEXISTENT)
return false; return false;
return true; return true;
} }

View File

@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Get a dependency-sorted list of ModSpecs // Get a dependency-sorted list of ModSpecs
core::list<ModSpec> getMods(core::list<std::string> &modspaths) core::list<ModSpec> getMods(core::list<std::string> &modspaths)
throw(ModError)
{ {
std::queue<ModSpec> mods_satisfied; std::queue<ModSpec> mods_satisfied;
core::list<ModSpec> mods_unsorted; core::list<ModSpec> mods_unsorted;

View File

@ -59,8 +59,7 @@ struct ModSpec
}; };
// Get a dependency-sorted list of ModSpecs // Get a dependency-sorted list of ModSpecs
core::list<ModSpec> getMods(core::list<std::string> &modspaths) core::list<ModSpec> getMods(core::list<std::string> &modspaths);
throw(ModError);
#endif #endif

View File

@ -139,14 +139,14 @@ static Server* get_server(lua_State *L)
return server; return server;
} }
static ServerEnvironment* get_env(lua_State *L) /*static ServerEnvironment* get_env(lua_State *L)
{ {
// Get environment from registry // Get environment from registry
lua_getfield(L, LUA_REGISTRYINDEX, "minetest_env"); lua_getfield(L, LUA_REGISTRYINDEX, "minetest_env");
ServerEnvironment *env = (ServerEnvironment*)lua_touserdata(L, -1); ServerEnvironment *env = (ServerEnvironment*)lua_touserdata(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
return env; return env;
} }*/
static void objectref_get(lua_State *L, u16 id) static void objectref_get(lua_State *L, u16 id)
{ {
@ -871,7 +871,7 @@ static ContentFeatures read_content_features(lua_State *L, int index)
f.alpha = getintfield_default(L, index, "alpha", 255); f.alpha = getintfield_default(L, index, "alpha", 255);
/* Other stuff */ /* Other stuff */
lua_getfield(L, index, "post_effect_color"); lua_getfield(L, index, "post_effect_color");
if(!lua_isnil(L, -1)) if(!lua_isnil(L, -1))
f.post_effect_color = readARGB8(L, -1); f.post_effect_color = readARGB8(L, -1);
@ -893,7 +893,7 @@ static ContentFeatures read_content_features(lua_State *L, int index)
"deprecated: use 'drop' field"); "deprecated: use 'drop' field");
warn_if_field_exists(L, index, "extra_dug_item_rarity", warn_if_field_exists(L, index, "extra_dug_item_rarity",
"deprecated: use 'drop' field"); "deprecated: use 'drop' field");
// True for all ground-like things like stone and mud, false for eg. trees // True for all ground-like things like stone and mud, false for eg. trees
getboolfield(L, index, "is_ground_content", f.is_ground_content); getboolfield(L, index, "is_ground_content", f.is_ground_content);
f.light_propagates = (f.param_type == CPT_LIGHT); f.light_propagates = (f.param_type == CPT_LIGHT);
@ -930,7 +930,7 @@ static ContentFeatures read_content_features(lua_State *L, int index)
"light_source", f.light_source); "light_source", f.light_source);
f.damage_per_second = getintfield_default(L, index, f.damage_per_second = getintfield_default(L, index,
"damage_per_second", f.damage_per_second); "damage_per_second", f.damage_per_second);
lua_getfield(L, index, "selection_box"); lua_getfield(L, index, "selection_box");
if(lua_istable(L, -1)){ if(lua_istable(L, -1)){
f.selection_box.type = (NodeBoxType)getenumfield(L, -1, "type", f.selection_box.type = (NodeBoxType)getenumfield(L, -1, "type",
@ -1060,7 +1060,7 @@ private:
static const luaL_reg methods[]; static const luaL_reg methods[];
// Exported functions // Exported functions
// garbage collector // garbage collector
static int gc_object(lua_State *L) static int gc_object(lua_State *L)
{ {
@ -1313,7 +1313,7 @@ public:
{ {
return m_stack; return m_stack;
} }
// LuaItemStack(itemstack or itemstring or table or nil) // LuaItemStack(itemstack or itemstring or table or nil)
// Creates an LuaItemStack and leaves it on top of stack // Creates an LuaItemStack and leaves it on top of stack
static int create_object(lua_State *L) static int create_object(lua_State *L)
@ -1463,7 +1463,7 @@ private:
if(!ud) luaL_typerror(L, narg, className); if(!ud) luaL_typerror(L, narg, className);
return *(InvRef**)ud; // unbox pointer return *(InvRef**)ud; // unbox pointer
} }
static Inventory* getinv(lua_State *L, InvRef *ref) static Inventory* getinv(lua_State *L, InvRef *ref)
{ {
return get_server(L)->getInventory(ref->m_loc); return get_server(L)->getInventory(ref->m_loc);
@ -1483,9 +1483,9 @@ private:
// Inform other things that the inventory has changed // Inform other things that the inventory has changed
get_server(L)->setInventoryModified(ref->m_loc); get_server(L)->setInventoryModified(ref->m_loc);
} }
// Exported functions // Exported functions
// garbage collector // garbage collector
static int gc_object(lua_State *L) { static int gc_object(lua_State *L) {
InvRef *o = *(InvRef **)(lua_touserdata(L, 1)); InvRef *o = *(InvRef **)(lua_touserdata(L, 1));
@ -1752,7 +1752,7 @@ private:
if(!ud) luaL_typerror(L, narg, className); if(!ud) luaL_typerror(L, narg, className);
return *(NodeMetaRef**)ud; // unbox pointer return *(NodeMetaRef**)ud; // unbox pointer
} }
static NodeMetadata* getmeta(NodeMetaRef *ref) static NodeMetadata* getmeta(NodeMetaRef *ref)
{ {
NodeMetadata *meta = ref->m_env->getMap().getNodeMetadata(ref->m_p); NodeMetadata *meta = ref->m_env->getMap().getNodeMetadata(ref->m_p);
@ -1783,9 +1783,9 @@ private:
block->raiseModified(MOD_STATE_WRITE_NEEDED, block->raiseModified(MOD_STATE_WRITE_NEEDED,
"NodeMetaRef::reportMetadataChange"); "NodeMetaRef::reportMetadataChange");
} }
// Exported functions // Exported functions
// garbage collector // garbage collector
static int gc_object(lua_State *L) { static int gc_object(lua_State *L) {
NodeMetaRef *o = *(NodeMetaRef **)(lua_touserdata(L, 1)); NodeMetaRef *o = *(NodeMetaRef **)(lua_touserdata(L, 1));
@ -1883,7 +1883,7 @@ private:
} }
/* IGenericNodeMetadata interface */ /* IGenericNodeMetadata interface */
// set_infotext(self, text) // set_infotext(self, text)
static int l_set_infotext(lua_State *L) static int l_set_infotext(lua_State *L)
{ {
@ -2128,13 +2128,13 @@ private:
if(!ud) luaL_typerror(L, narg, className); if(!ud) luaL_typerror(L, narg, className);
return *(ObjectRef**)ud; // unbox pointer return *(ObjectRef**)ud; // unbox pointer
} }
static ServerActiveObject* getobject(ObjectRef *ref) static ServerActiveObject* getobject(ObjectRef *ref)
{ {
ServerActiveObject *co = ref->m_object; ServerActiveObject *co = ref->m_object;
return co; return co;
} }
static LuaEntitySAO* getluaobject(ObjectRef *ref) static LuaEntitySAO* getluaobject(ObjectRef *ref)
{ {
ServerActiveObject *obj = getobject(ref); ServerActiveObject *obj = getobject(ref);
@ -2144,7 +2144,7 @@ private:
return NULL; return NULL;
return (LuaEntitySAO*)obj; return (LuaEntitySAO*)obj;
} }
static ServerRemotePlayer* getplayer(ObjectRef *ref) static ServerRemotePlayer* getplayer(ObjectRef *ref)
{ {
ServerActiveObject *obj = getobject(ref); ServerActiveObject *obj = getobject(ref);
@ -2154,9 +2154,9 @@ private:
return NULL; return NULL;
return static_cast<ServerRemotePlayer*>(obj); return static_cast<ServerRemotePlayer*>(obj);
} }
// Exported functions // Exported functions
// garbage collector // garbage collector
static int gc_object(lua_State *L) { static int gc_object(lua_State *L) {
ObjectRef *o = *(ObjectRef **)(lua_touserdata(L, 1)); ObjectRef *o = *(ObjectRef **)(lua_touserdata(L, 1));
@ -2175,7 +2175,7 @@ private:
co->m_removed = true; co->m_removed = true;
return 0; return 0;
} }
// getpos(self) // getpos(self)
// returns: {x=num, y=num, z=num} // returns: {x=num, y=num, z=num}
static int l_getpos(lua_State *L) static int l_getpos(lua_State *L)
@ -2193,7 +2193,7 @@ private:
lua_setfield(L, -2, "z"); lua_setfield(L, -2, "z");
return 1; return 1;
} }
// setpos(self, pos) // setpos(self, pos)
static int l_setpos(lua_State *L) static int l_setpos(lua_State *L)
{ {
@ -2211,7 +2211,7 @@ private:
get_server(L)->SendMovePlayer(player); get_server(L)->SendMovePlayer(player);
return 0; return 0;
} }
// moveto(self, pos, continuous=false) // moveto(self, pos, continuous=false)
static int l_moveto(lua_State *L) static int l_moveto(lua_State *L)
{ {
@ -2365,7 +2365,7 @@ private:
co->setVelocity(pos); co->setVelocity(pos);
return 0; return 0;
} }
// getvelocity(self) // getvelocity(self)
static int l_getvelocity(lua_State *L) static int l_getvelocity(lua_State *L)
{ {
@ -2377,7 +2377,7 @@ private:
pushFloatPos(L, v); pushFloatPos(L, v);
return 1; return 1;
} }
// setacceleration(self, {x=num, y=num, z=num}) // setacceleration(self, {x=num, y=num, z=num})
static int l_setacceleration(lua_State *L) static int l_setacceleration(lua_State *L)
{ {
@ -2390,7 +2390,7 @@ private:
co->setAcceleration(pos); co->setAcceleration(pos);
return 0; return 0;
} }
// getacceleration(self) // getacceleration(self)
static int l_getacceleration(lua_State *L) static int l_getacceleration(lua_State *L)
{ {
@ -2402,7 +2402,7 @@ private:
pushFloatPos(L, v); pushFloatPos(L, v);
return 1; return 1;
} }
// setyaw(self, radians) // setyaw(self, radians)
static int l_setyaw(lua_State *L) static int l_setyaw(lua_State *L)
{ {
@ -2415,7 +2415,7 @@ private:
co->setYaw(yaw); co->setYaw(yaw);
return 0; return 0;
} }
// getyaw(self) // getyaw(self)
static int l_getyaw(lua_State *L) static int l_getyaw(lua_State *L)
{ {
@ -2427,7 +2427,7 @@ private:
lua_pushnumber(L, yaw); lua_pushnumber(L, yaw);
return 1; return 1;
} }
// settexturemod(self, mod) // settexturemod(self, mod)
static int l_settexturemod(lua_State *L) static int l_settexturemod(lua_State *L)
{ {
@ -2439,7 +2439,7 @@ private:
co->setTextureMod(mod); co->setTextureMod(mod);
return 0; return 0;
} }
// setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2, // setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
// select_horiz_by_yawpitch=false) // select_horiz_by_yawpitch=false)
static int l_setsprite(lua_State *L) static int l_setsprite(lua_State *L)
@ -2476,7 +2476,7 @@ private:
lua_pushstring(L, name.c_str()); lua_pushstring(L, name.c_str());
return 1; return 1;
} }
// get_luaentity(self) // get_luaentity(self)
static int l_get_luaentity(lua_State *L) static int l_get_luaentity(lua_State *L)
{ {
@ -2487,9 +2487,9 @@ private:
luaentity_get(L, co->getId()); luaentity_get(L, co->getId());
return 1; return 1;
} }
/* Player-only */ /* Player-only */
// get_player_name(self) // get_player_name(self)
static int l_get_player_name(lua_State *L) static int l_get_player_name(lua_State *L)
{ {
@ -2503,7 +2503,7 @@ private:
lua_pushstring(L, player->getName()); lua_pushstring(L, player->getName());
return 1; return 1;
} }
// get_look_dir(self) // get_look_dir(self)
static int l_get_look_dir(lua_State *L) static int l_get_look_dir(lua_State *L)
{ {
@ -2572,7 +2572,7 @@ public:
ObjectRef *o = checkobject(L, -1); ObjectRef *o = checkobject(L, -1);
o->m_object = NULL; o->m_object = NULL;
} }
static void Register(lua_State *L) static void Register(lua_State *L)
{ {
lua_newtable(L); lua_newtable(L);
@ -2666,7 +2666,7 @@ private:
if(!ud) luaL_typerror(L, narg, className); if(!ud) luaL_typerror(L, narg, className);
return *(EnvRef**)ud; // unbox pointer return *(EnvRef**)ud; // unbox pointer
} }
// Exported functions // Exported functions
// EnvRef:add_node(pos, node) // EnvRef:add_node(pos, node)
@ -2947,7 +2947,7 @@ public:
EnvRef *o = checkobject(L, -1); EnvRef *o = checkobject(L, -1);
o->m_env = NULL; o->m_env = NULL;
} }
static void Register(lua_State *L) static void Register(lua_State *L)
{ {
lua_newtable(L); lua_newtable(L);
@ -3040,7 +3040,7 @@ public:
u32 active_object_count, u32 active_object_count_wider) u32 active_object_count, u32 active_object_count_wider)
{ {
lua_State *L = m_lua; lua_State *L = m_lua;
realitycheck(L); realitycheck(L);
assert(lua_checkstack(L, 20)); assert(lua_checkstack(L, 20));
StackUnroller stack_unroller(L); StackUnroller stack_unroller(L);
@ -3056,7 +3056,7 @@ public:
lua_gettable(L, registered_abms); lua_gettable(L, registered_abms);
if(lua_isnil(L, -1)) if(lua_isnil(L, -1))
assert(0); assert(0);
// Call action // Call action
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
lua_getfield(L, -1, "action"); lua_getfield(L, -1, "action");
@ -3152,9 +3152,9 @@ static int l_register_alias_raw(lua_State *L)
// Get the writable item definition manager from the server // Get the writable item definition manager from the server
IWritableItemDefManager *idef = IWritableItemDefManager *idef =
get_server(L)->getWritableItemDefManager(); get_server(L)->getWritableItemDefManager();
idef->registerAlias(name, convert_to); idef->registerAlias(name, convert_to);
return 0; /* number of results */ return 0; /* number of results */
} }
@ -3263,7 +3263,7 @@ static int l_register_craft(lua_State *L)
// Get the writable craft definition manager from the server // Get the writable craft definition manager from the server
IWritableCraftDefManager *craftdef = IWritableCraftDefManager *craftdef =
get_server(L)->getWritableCraftDefManager(); get_server(L)->getWritableCraftDefManager();
std::string type = getstringfield_default(L, table, "type", "shaped"); std::string type = getstringfield_default(L, table, "type", "shaped");
/* /*
@ -3471,7 +3471,7 @@ static int l_get_inventory(lua_State *L)
v3s16 pos = check_v3s16(L, -1); v3s16 pos = check_v3s16(L, -1);
loc.setNodeMeta(pos); loc.setNodeMeta(pos);
} }
if(get_server(L)->getInventory(loc) != NULL) if(get_server(L)->getInventory(loc) != NULL)
InvRef::create(L, loc); InvRef::create(L, loc);
else else
@ -3564,12 +3564,12 @@ void scriptapi_export(lua_State *L, Server *server)
lua_newtable(L); lua_newtable(L);
luaL_register(L, NULL, minetest_f); luaL_register(L, NULL, minetest_f);
lua_setglobal(L, "minetest"); lua_setglobal(L, "minetest");
// Get the main minetest table // Get the main minetest table
lua_getglobal(L, "minetest"); lua_getglobal(L, "minetest");
// Add tables to minetest // Add tables to minetest
lua_newtable(L); lua_newtable(L);
lua_setfield(L, -2, "object_refs"); lua_setfield(L, -2, "object_refs");
lua_newtable(L); lua_newtable(L);
@ -3595,7 +3595,7 @@ bool scriptapi_loadmod(lua_State *L, const std::string &scriptpath,
<<"Only chararacters [a-z0-9_] are allowed."<<std::endl; <<"Only chararacters [a-z0-9_] are allowed."<<std::endl;
return false; return false;
} }
bool success = false; bool success = false;
try{ try{
@ -3639,7 +3639,7 @@ void scriptapi_add_environment(lua_State *L, ServerEnvironment *env)
lua_getfield(L, -1, "registered_abms"); lua_getfield(L, -1, "registered_abms");
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
int registered_abms = lua_gettop(L); int registered_abms = lua_gettop(L);
if(lua_istable(L, registered_abms)){ if(lua_istable(L, registered_abms)){
int table = lua_gettop(L); int table = lua_gettop(L);
lua_pushnil(L); lua_pushnil(L);
@ -3690,7 +3690,7 @@ void scriptapi_add_environment(lua_State *L, ServerEnvironment *env)
LuaABM *abm = new LuaABM(L, id, trigger_contents, LuaABM *abm = new LuaABM(L, id, trigger_contents,
required_neighbors, trigger_interval, trigger_chance); required_neighbors, trigger_interval, trigger_chance);
env->addActiveBlockModifier(abm); env->addActiveBlockModifier(abm);
// removes value, keeps key for next iteration // removes value, keeps key for next iteration
@ -3734,7 +3734,7 @@ void scriptapi_add_object_reference(lua_State *L, ServerActiveObject *cobj)
lua_getfield(L, -1, "object_refs"); lua_getfield(L, -1, "object_refs");
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
int objectstable = lua_gettop(L); int objectstable = lua_gettop(L);
// object_refs[id] = object // object_refs[id] = object
lua_pushnumber(L, cobj->getId()); // Push id lua_pushnumber(L, cobj->getId()); // Push id
lua_pushvalue(L, object); // Copy object to top of stack lua_pushvalue(L, object); // Copy object to top of stack
@ -3753,7 +3753,7 @@ void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj)
lua_getfield(L, -1, "object_refs"); lua_getfield(L, -1, "object_refs");
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
int objectstable = lua_gettop(L); int objectstable = lua_gettop(L);
// Get object_refs[id] // Get object_refs[id]
lua_pushnumber(L, cobj->getId()); // Push id lua_pushnumber(L, cobj->getId()); // Push id
lua_gettable(L, objectstable); lua_gettable(L, objectstable);
@ -3831,7 +3831,7 @@ void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player)
realitycheck(L); realitycheck(L);
assert(lua_checkstack(L, 20)); assert(lua_checkstack(L, 20));
StackUnroller stack_unroller(L); StackUnroller stack_unroller(L);
// Get minetest.registered_on_dieplayers // Get minetest.registered_on_dieplayers
lua_getglobal(L, "minetest"); lua_getglobal(L, "minetest");
lua_getfield(L, -1, "registered_on_dieplayers"); lua_getfield(L, -1, "registered_on_dieplayers");
@ -4115,7 +4115,7 @@ bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name,
infostream<<"scriptapi_luaentity_add: id="<<id<<" name=\"" infostream<<"scriptapi_luaentity_add: id="<<id<<" name=\""
<<name<<"\""<<std::endl; <<name<<"\""<<std::endl;
StackUnroller stack_unroller(L); StackUnroller stack_unroller(L);
// Get minetest.registered_entities[name] // Get minetest.registered_entities[name]
lua_getglobal(L, "minetest"); lua_getglobal(L, "minetest");
lua_getfield(L, -1, "registered_entities"); lua_getfield(L, -1, "registered_entities");
@ -4130,7 +4130,7 @@ bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name,
} }
int prototype_table = lua_gettop(L); int prototype_table = lua_gettop(L);
//dump2(L, "prototype_table"); //dump2(L, "prototype_table");
// Create entity object // Create entity object
lua_newtable(L); lua_newtable(L);
int object = lua_gettop(L); int object = lua_gettop(L);
@ -4138,7 +4138,7 @@ bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name,
// Set object metatable // Set object metatable
lua_pushvalue(L, prototype_table); lua_pushvalue(L, prototype_table);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
// Add object reference // Add object reference
// This should be userdata with metatable ObjectRef // This should be userdata with metatable ObjectRef
objectref_get(L, id); objectref_get(L, id);
@ -4154,7 +4154,7 @@ bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name,
lua_pushnumber(L, id); // Push id lua_pushnumber(L, id); // Push id
lua_pushvalue(L, object); // Copy object to top of stack lua_pushvalue(L, object); // Copy object to top of stack
lua_settable(L, -3); lua_settable(L, -3);
// Get on_activate function // Get on_activate function
lua_pushvalue(L, object); lua_pushvalue(L, object);
lua_getfield(L, -1, "on_activate"); lua_getfield(L, -1, "on_activate");
@ -4167,7 +4167,7 @@ bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name,
script_error(L, "error running function %s:on_activate: %s\n", script_error(L, "error running function %s:on_activate: %s\n",
name, lua_tostring(L, -1)); name, lua_tostring(L, -1));
} }
return true; return true;
} }
@ -4182,12 +4182,12 @@ void scriptapi_luaentity_rm(lua_State *L, u16 id)
lua_getfield(L, -1, "luaentities"); lua_getfield(L, -1, "luaentities");
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
int objectstable = lua_gettop(L); int objectstable = lua_gettop(L);
// Set luaentities[id] = nil // Set luaentities[id] = nil
lua_pushnumber(L, id); // Push id lua_pushnumber(L, id); // Push id
lua_pushnil(L); lua_pushnil(L);
lua_settable(L, objectstable); lua_settable(L, objectstable);
lua_pop(L, 2); // pop luaentities, minetest lua_pop(L, 2); // pop luaentities, minetest
} }
@ -4201,20 +4201,20 @@ std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id)
// Get minetest.luaentities[id] // Get minetest.luaentities[id]
luaentity_get(L, id); luaentity_get(L, id);
int object = lua_gettop(L); int object = lua_gettop(L);
// Get get_staticdata function // Get get_staticdata function
lua_pushvalue(L, object); lua_pushvalue(L, object);
lua_getfield(L, -1, "get_staticdata"); lua_getfield(L, -1, "get_staticdata");
if(lua_isnil(L, -1)) if(lua_isnil(L, -1))
return ""; return "";
luaL_checktype(L, -1, LUA_TFUNCTION); luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self lua_pushvalue(L, object); // self
// Call with 1 arguments, 1 results // Call with 1 arguments, 1 results
if(lua_pcall(L, 1, 1, 0)) if(lua_pcall(L, 1, 1, 0))
script_error(L, "error running function get_staticdata: %s\n", script_error(L, "error running function get_staticdata: %s\n",
lua_tostring(L, -1)); lua_tostring(L, -1));
size_t len=0; size_t len=0;
const char *s = lua_tolstring(L, -1, &len); const char *s = lua_tolstring(L, -1, &len);
return std::string(s, len); return std::string(s, len);
@ -4233,7 +4233,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
//int object = lua_gettop(L); //int object = lua_gettop(L);
/* Read stuff */ /* Read stuff */
getboolfield(L, -1, "physical", prop->physical); getboolfield(L, -1, "physical", prop->physical);
getfloatfield(L, -1, "weight", prop->weight); getfloatfield(L, -1, "weight", prop->weight);
@ -4244,7 +4244,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
lua_pop(L, 1); lua_pop(L, 1);
getstringfield(L, -1, "visual", prop->visual); getstringfield(L, -1, "visual", prop->visual);
lua_getfield(L, -1, "visual_size"); lua_getfield(L, -1, "visual_size");
if(lua_istable(L, -1)) if(lua_istable(L, -1))
prop->visual_size = read_v2f(L, -1); prop->visual_size = read_v2f(L, -1);
@ -4266,7 +4266,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
} }
} }
lua_pop(L, 1); lua_pop(L, 1);
lua_getfield(L, -1, "spritediv"); lua_getfield(L, -1, "spritediv");
if(lua_istable(L, -1)) if(lua_istable(L, -1))
prop->spritediv = read_v2s16(L, -1); prop->spritediv = read_v2s16(L, -1);

View File

@ -54,14 +54,14 @@ void cmd_privs(std::wostringstream &os,
os<<L"-!- You don't have permission to do that"; os<<L"-!- You don't have permission to do that";
return; return;
} }
Player *tp = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str()); Player *tp = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
if(tp == NULL) if(tp == NULL)
{ {
os<<L"-!- No such player"; os<<L"-!- No such player";
return; return;
} }
os<<L"-!- " + narrow_to_wide(privsToString(ctx->server->getPlayerAuthPrivs(tp->getName()))); os<<L"-!- " + narrow_to_wide(privsToString(ctx->server->getPlayerAuthPrivs(tp->getName())));
} }
@ -93,7 +93,7 @@ void cmd_grantrevoke(std::wostringstream &os,
os<<L"-!- No such player"; os<<L"-!- No such player";
return; return;
} }
std::string playername = wide_to_narrow(ctx->parms[1]); std::string playername = wide_to_narrow(ctx->parms[1]);
u64 privs = ctx->server->getPlayerAuthPrivs(playername); u64 privs = ctx->server->getPlayerAuthPrivs(playername);
@ -122,9 +122,9 @@ void cmd_grantrevoke(std::wostringstream &os,
msg += L"\""; msg += L"\"";
ctx->server->notifyPlayer(playername.c_str(), msg); ctx->server->notifyPlayer(playername.c_str(), msg);
} }
ctx->server->setPlayerAuthPrivs(playername, privs); ctx->server->setPlayerAuthPrivs(playername, privs);
os<<L"-!- Privileges change to "; os<<L"-!- Privileges change to ";
os<<narrow_to_wide(privsToString(privs)); os<<narrow_to_wide(privsToString(privs));
} }
@ -165,7 +165,7 @@ void cmd_shutdown(std::wostringstream &os,
<<" shuts down server"<<std::endl; <<" shuts down server"<<std::endl;
ctx->server->requestShutdown(); ctx->server->requestShutdown();
os<<L"*** Server shutting down (operator request)"; os<<L"*** Server shutting down (operator request)";
ctx->flags |= SEND_TO_OTHERS; ctx->flags |= SEND_TO_OTHERS;
} }
@ -183,12 +183,12 @@ void cmd_setting(std::wostringstream &os,
ctx->parms[1] + L" = " + ctx->params[2]);*/ ctx->parms[1] + L" = " + ctx->params[2]);*/
std::string confline = wide_to_narrow(ctx->paramstring); std::string confline = wide_to_narrow(ctx->paramstring);
actionstream<<ctx->player->getName() actionstream<<ctx->player->getName()
<<" sets: "<<confline<<std::endl; <<" sets: "<<confline<<std::endl;
g_settings->parseConfigLine(confline); g_settings->parseConfigLine(confline);
ctx->server->saveConfig(); ctx->server->saveConfig();
os<< L"-!- Setting changed and configuration saved."; os<< L"-!- Setting changed and configuration saved.";
@ -255,7 +255,7 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
os<<L"-!- No such player"; os<<L"-!- No such player";
return; return;
} }
try{ try{
Address address = ctx->server->getPeerAddress(player->peer_id); Address address = ctx->server->getPeerAddress(player->peer_id);
std::string ip_string = address.serializeString(); std::string ip_string = address.serializeString();
@ -265,7 +265,7 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
actionstream<<ctx->player->getName()<<" bans " actionstream<<ctx->player->getName()<<" bans "
<<player->getName()<<" / "<<ip_string<<std::endl; <<player->getName()<<" / "<<ip_string<<std::endl;
} catch(con::PeerNotFoundException){ } catch(con::PeerNotFoundException &){
dstream<<__FUNCTION_NAME<<": peer was not found"<<std::endl; dstream<<__FUNCTION_NAME<<": peer was not found"<<std::endl;
} }
} }
@ -344,7 +344,7 @@ void cmd_clearobjects(std::wostringstream &os,
actionstream<<ctx->player->getName() actionstream<<ctx->player->getName()
<<" clears all objects"<<std::endl; <<" clears all objects"<<std::endl;
{ {
std::wstring msg; std::wstring msg;
msg += L"Clearing all objects. This may take long."; msg += L"Clearing all objects. This may take long.";
@ -355,9 +355,9 @@ void cmd_clearobjects(std::wostringstream &os,
} }
ctx->env->clearAllObjects(); ctx->env->clearAllObjects();
actionstream<<"object clearing done"<<std::endl; actionstream<<"object clearing done"<<std::endl;
os<<L"*** cleared all objects"; os<<L"*** cleared all objects";
ctx->flags |= SEND_TO_OTHERS; ctx->flags |= SEND_TO_OTHERS;
} }
@ -412,7 +412,7 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
cmd_clearobjects(os, ctx); cmd_clearobjects(os, ctx);
else else
os<<L"-!- Invalid command: " + ctx->parms[0]; os<<L"-!- Invalid command: " + ctx->parms[0];
return os.str(); return os.str();
} }