From a04aad0df3c902b189ac3ece7e176950e7ffb78e Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 18 Nov 2011 21:04:08 +0000 Subject: [PATCH] (svn r23255) [1.1] -Backport from trunk: - Fix: When any keys on the on-screen keyboard were pressed the text cursor disappeared (r23132) - Fix: [NoAI] AIOrder::IsCurrentOrderPartOfOrderList return false for valid vehicles and crashed for invalid ones (r23131) - Fix: [NoAI] calling require() to include a file gave you 100.000 opcodes for free (r23117) - Fix: Allow accessing the server's client info as well in the admin network [FS#4813] (r23115) --- bin/ai/regression/regression.txt | 10 +++++----- src/ai/api/ai_order.cpp | 2 +- src/network/network_admin.cpp | 23 ++++++++++++++++------- src/network/network_admin.h | 2 +- src/osk_gui.cpp | 12 ++++++------ src/script/squirrel.cpp | 4 ++++ 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index 7096672161..af217d95ae 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -8456,7 +8456,7 @@ ERROR: IsEnd() is invalid as Begin() is never called GetNumWagons(): 3 GetLength(): 24 GetWagonEngineType(): 9 - GetWagonAge(): 0 + GetWagonAge(): 1 GetWagonEngineType(): 27 GetWagonAge(): 0 GetWagonEngineType(): 27 @@ -8492,11 +8492,11 @@ ERROR: IsEnd() is invalid as Begin() is never called 14 => 1 12 => 1 Age ListDump: + 17 => 1 + 16 => 1 14 => 1 13 => 1 12 => 1 - 17 => 0 - 16 => 0 MaxAge ListDump: 16 => 10980 14 => 10980 @@ -8504,9 +8504,9 @@ ERROR: IsEnd() is invalid as Begin() is never called 13 => 5490 12 => 5490 AgeLeft ListDump: - 16 => 10980 + 16 => 10979 14 => 10979 - 17 => 7320 + 17 => 7319 13 => 5489 12 => 5489 CurrentSpeed ListDump: diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp index a26a0dc20d..4bad055724 100644 --- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -119,7 +119,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or /* static */ bool AIOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id) { - if (AIVehicle::IsValidVehicle(vehicle_id)) return false; + if (!AIVehicle::IsValidVehicle(vehicle_id)) return false; if (GetOrderCount(vehicle_id) == 0) return false; const Order *order = &::Vehicle::Get(vehicle_id)->current_order; diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 76682b3c2c..bdb4892ce5 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -199,16 +199,20 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin(ClientID clien return NETWORK_RECV_STATUS_OKAY; } -NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs) +/** + * Send an initial set of data from some client's information. + * @param cs The socket of the client. + * @param ci The information about the client. + */ +NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci) { /* Only send data when we're a proper client, not just someone trying to query the server. */ - const NetworkClientInfo *ci = cs->GetInfo(); if (ci == NULL) return NETWORK_RECV_STATUS_OKAY; Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_INFO); p->Send_uint32(ci->client_id); - p->Send_string(const_cast(cs->client_address).GetHostname()); + p->Send_string(cs == NULL ? "" : const_cast(cs->client_address).GetHostname()); p->Send_string(ci->client_name); p->Send_uint8 (ci->client_lang); p->Send_uint32(ci->join_date); @@ -571,12 +575,17 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_POLL) /* The admin is requesting client info. */ const NetworkClientSocket *cs; if (d1 == UINT32_MAX) { + this->SendClientInfo(NULL, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER)); FOR_ALL_CLIENT_SOCKETS(cs) { - this->SendClientInfo(cs); + this->SendClientInfo(cs, cs->GetInfo()); } } else { - cs = NetworkClientSocket::GetByClientID((ClientID)d1); - if (cs != NULL) this->SendClientInfo(cs); + if (d1 == CLIENT_ID_SERVER) { + this->SendClientInfo(NULL, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER)); + } else { + cs = NetworkClientSocket::GetByClientID((ClientID)d1); + if (cs != NULL) this->SendClientInfo(cs, cs->GetInfo()); + } } break; @@ -658,7 +667,7 @@ void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client) ServerNetworkAdminSocketHandler *as; FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) { if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) { - as->SendClientInfo(cs); + as->SendClientInfo(cs, cs->GetInfo()); if (new_client) { as->SendClientJoin(cs->client_id); } diff --git a/src/network/network_admin.h b/src/network/network_admin.h index 2f679638a4..87e9ab094b 100644 --- a/src/network/network_admin.h +++ b/src/network/network_admin.h @@ -50,7 +50,7 @@ public: NetworkRecvStatus SendDate(); NetworkRecvStatus SendClientJoin(ClientID client_id); - NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs); + NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci); NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci); NetworkRecvStatus SendClientQuit(ClientID client_id); NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error); diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp index cd323b362c..001251790a 100644 --- a/src/osk_gui.cpp +++ b/src/osk_gui.cpp @@ -157,16 +157,13 @@ struct OskWindow : public Window { this->GetWidget(OSK_WIDGET_SHIFT)->colour = HasBit(_keystate, KEYS_SHIFT) ? COLOUR_WHITE : COLOUR_GREY; this->SetDirty(); } + /* Return focus to the parent widget and window. */ + this->parent->SetFocusedWidget(this->text_btn); + SetFocusedWindow(this->parent); return; } switch (widget) { - case OSK_WIDGET_TEXT: - /* Return focus to the parent widget and window. */ - this->parent->SetFocusedWidget(this->text_btn); - SetFocusedWindow(this->parent); - break; - case OSK_WIDGET_BACKSPACE: if (DeleteTextBufferChar(&this->qs->text, WKC_BACKSPACE)) this->InvalidateParent(); break; @@ -229,6 +226,9 @@ struct OskWindow : public Window { } break; } + /* Return focus to the parent widget and window. */ + this->parent->SetFocusedWidget(this->text_btn); + SetFocusedWindow(this->parent); } void InvalidateParent() diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index b9151e727e..890630eeb7 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -481,15 +481,19 @@ static SQInteger _io_file_read(SQUserPointer file, SQUserPointer buf, SQInteger /* Make sure we are always in the root-table */ if (in_root) sq_pushroottable(vm); + SQInteger ops_left = vm->_ops_till_suspend; /* Load and run the script */ if (SQ_SUCCEEDED(LoadFile(vm, script, SQTrue))) { sq_push(vm, -2); if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue, 100000))) { sq_pop(vm, 1); + /* After compiling the file we want to reset the amount of opcodes. */ + vm->_ops_till_suspend = ops_left; return true; } } + vm->_ops_till_suspend = ops_left; DEBUG(misc, 0, "[squirrel] Failed to compile '%s'", script); return false; }