Index: src/network/core/udp.cpp =================================================================== --- src/network/core/udp.cpp (revision 27096) +++ src/network/core/udp.cpp (working copy) @@ -312,6 +312,8 @@ case PACKET_UDP_SERVER_UNREGISTER: this->Receive_SERVER_UNREGISTER(p, client_addr); break; case PACKET_UDP_CLIENT_GET_NEWGRFS: this->Receive_CLIENT_GET_NEWGRFS(p, client_addr); break; case PACKET_UDP_SERVER_NEWGRFS: this->Receive_SERVER_NEWGRFS(p, client_addr); break; + case PACKET_UDP_CLIENT_GET_GAMESCRIPT: this->Receive_CLIENT_GET_GAMESCRIPT(p, client_addr); break; + case PACKET_UDP_SERVER_GAMESCRIPT: this->Receive_SERVER_GAMESCRIPT(p, client_addr); break; case PACKET_UDP_MASTER_SESSION_KEY: this->Receive_MASTER_SESSION_KEY(p, client_addr); break; default: @@ -345,6 +347,8 @@ void NetworkUDPSocketHandler::Receive_SERVER_UNREGISTER(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_UNREGISTER, client_addr); } void NetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_GET_NEWGRFS, client_addr); } void NetworkUDPSocketHandler::Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_NEWGRFS, client_addr); } +void NetworkUDPSocketHandler::Receive_CLIENT_GET_GAMESCRIPT(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_GET_GAMESCRIPT, client_addr); } +void NetworkUDPSocketHandler::Receive_SERVER_GAMESCRIPT(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_GAMESCRIPT , client_addr); } void NetworkUDPSocketHandler::Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_MASTER_SESSION_KEY, client_addr); } #endif /* ENABLE_NETWORK */ Index: src/network/core/udp.h =================================================================== --- src/network/core/udp.h (revision 27096) +++ src/network/core/udp.h (working copy) @@ -34,6 +34,8 @@ PACKET_UDP_CLIENT_GET_NEWGRFS, ///< Requests the name for a list of GRFs (GRF_ID and MD5) PACKET_UDP_SERVER_NEWGRFS, ///< Sends the list of NewGRF's requested. PACKET_UDP_MASTER_SESSION_KEY, ///< Sends a fresh session key to the client + PACKET_UDP_CLIENT_GET_GAMESCRIPT,///< Requests the name of a game script + PACKET_UDP_SERVER_GAMESCRIPT, ///< Sends the gamescript info PACKET_UDP_END, ///< Must ALWAYS be on the end of this list!! (period) }; @@ -213,6 +215,24 @@ virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr); /** + * The client requests information about GameScript. + * @param p The received packet. + * @param client_addr The origin of the packet. + */ + virtual void Receive_CLIENT_GET_GAMESCRIPT(Packet *p, NetworkAddress *client_addr); + + /** + * The server returns information about gamescript. + * uint8 Numer of GameScripts (0 or 1). + * uint32 Version of GameScript + * string Short name of GameScript (4 bytes) + * string The name of the GameScript. + * @param p The received packet. + * @param client_addr The origin of the packet. + */ + virtual void Receive_SERVER_GAMESCRIPT(Packet *p, NetworkAddress *client_addr); + + /** * The master server sends us a session key. * uint64 The session key. * @param p The received packet. Index: src/network/network_udp.cpp =================================================================== --- src/network/network_udp.cpp (revision 27096) +++ src/network/network_udp.cpp (working copy) @@ -31,6 +31,8 @@ #include "../newgrf_text.h" #include "../strings_func.h" #include "table/strings.h" +#include "../game/game.hpp" +#include "../game/game_info.hpp" #include "core/udp.h" @@ -153,6 +155,7 @@ virtual void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr); virtual void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr); virtual void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr); + virtual void Receive_CLIENT_GET_GAMESCRIPT(Packet *p, NetworkAddress *client_addr); public: /** * Create the socket. @@ -321,6 +324,29 @@ this->SendPacket(&packet, client_addr); } +/** + * A client has requested the name of GameScript. + */ +void ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_GAMESCRIPT(Packet *p, NetworkAddress *client_addr) +{ + DEBUG(net, 6, "[udp] gamescript data request from %s", client_addr->GetAddressAsString()); + + GameInfo *info = Game::GetInfo(); + + Packet packet(PACKET_UDP_SERVER_GAMESCRIPT); + if(info == NULL){ + packet.Send_uint8(0); + } + else{ + packet.Send_uint8(1); + packet.Send_uint32((uint32)info->GetVersion()); + packet.Send_string(info->GetShortName()); + packet.Send_string(info->GetName()); + } + + this->SendPacket(&packet, client_addr); +} + ///*** Communication with servers (we are client) ***/ /** Helper class for handling all client side communication. */ @@ -329,6 +355,7 @@ virtual void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr); virtual void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr); virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr); + virtual void Receive_SERVER_GAMESCRIPT(Packet *p, NetworkAddress *client_addr); virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config); public: virtual ~ClientNetworkUDPSocketHandler() {} @@ -467,6 +494,25 @@ } } +/** The return of the client's request of the names of GameScript */ +void ClientNetworkUDPSocketHandler::Receive_SERVER_GAMESCRIPT(Packet *p, NetworkAddress *client_addr) +{ + uint8 num_gs; + + DEBUG(net, 6, "[udp] gamescript data reply from %s", client_addr->GetAddressAsString()); + + num_gs = p->Recv_uint8(); + if (num_gs != 1) return; + + int version = (int)p->Recv_uint32(); + + char shortname[8]; + char name[NETWORK_GRF_NAME_LENGTH]; + + p->Recv_string(shortname, sizeof(shortname)); + p->Recv_string(name, sizeof(name)); +} + void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) { /* Find the matching GRF file */