I give you the first patch I wrote that was functional on 3.0rc1/-. You will find the code required to get rid of wininet. I include only standard C/C++ stuff and network/core/tcp_http.h which contains the declaration of the HTTPCallback class, the OpenTTD's internal HTTP client facility.
diff -ru openttd-1.3.0-RC1/src/network/network_chat_gui.cpp openttd-1.3.0-RC1-btpro/src/network/network_chat_gui.cpp
--- openttd-1.3.0-RC1/src/network/network_chat_gui.cpp 2013-02-19 15:08:33.000000000 -0500
+++ openttd-1.3.0-RC1-btpro/src/network/network_chat_gui.cpp 2013-03-02 02:05:31.506887601 -0500
@@ -267,6 +267,101 @@
_chatmessage_dirty = false;
}
+#include <stdio.h>
+#include <ctype.h>
+#include "core/tcp_http.h"
+#include <iostream>
+
+static void SendChat(const char *buf, DestType type, int dest);
+
+class BTProAccountManager: public HTTPCallback {
+public:
+ BTProAccountManager(const char *u, const char *p): username(u), password(p), is_btpro_server(0) {}
+
+ int onServerConnectHandler() {
+ if (strcmp(_settings_client.network.last_host, "83.137.149.29") && // main server
+ strcmp(_settings_client.network.last_host, "95.97.242.6")) { // 1.3rc1 test server
+ this->is_btpro_server = false;
+ IConsolePrint( CC_INFO, "*** NOT A BTPRO SERVER ***");
+ } else {
+ char b[256];
+ this->is_btpro_server = _settings_client.network.last_port - 3980;
+ snprintf(b, 256, "*** BTPRO SERVER #%d ***", this->is_btpro_server);
+ }
+ return this->is_btpro_server;
+ }
+
+ int isBTProServer() {
+ return this->is_btpro_server;
+ }
+
+ void initiateLoginSequence() {
+ char uri[512];
+ IConsolePrint(CC_INFO, "INITIATING LOGIN SEQUENCE");
+ snprintf(uri, 512, "
openttd.btpro.nl/gettoken.php?user=%s&password=%s", this->username, this->password);
+ std::cout << "sending to http server: " << uri << std::endl;
+ this->cursor = this->buf;
+ NetworkHTTPSocketHandler::Connect(uri, this, 0, 0);
+ }
+
+ void sendLoginString() {
+ char b[16];
+ snprintf(b, 16, "!login %s", this->buf);
+ SendChat(b, DESTTYPE_CLIENT, 1);
+ IConsolePrint( CC_INFO, "LOGIN STRING SENT");
+ }
+
+ void inspectLoginData() {
+ IConsolePrint(CC_INFO, "INSPECTING DATA");
+ if (this->cursor - this->buf == 4) {
+ this->sendLoginString();
+ IConsolePrint( CC_INFO, "*** BTPRO Authentification successful ***");
+ }
+ else {
+ char b[512];
+ snprintf(b, 512, "*** BTPRO Authentification failed: %s", this->buf);
+ IConsolePrint(CC_ERROR, b);
+ }
+
+ }
+
+ virtual void OnFailure() {
+ std::cout << "*** UNABLE TO RETRIEVE BTPRO LOGIN TOKEN FROM HTTP SERVER ***" << std::endl;
+ }
+
+ virtual void OnReceiveData( const char *data, size_t length) {
+ size_t i = length;
+
+ if (data == 0) {
+ std::cout << "*** RECEIVED ALL HTTP DATA ***" << std::endl;
+ this->inspectLoginData();
+ this->cursor = 0;
+ } else {
+ std::cout << "*** RECEIVING HTTP DATA ***" << std::endl;
+ while ( this->cursor - this->buf < 512 && i) {
+ *this->cursor = *data;
+ data++;
+ this->cursor++;
+ i--;
+ }
+ if (this->cursor - this->buf >= 512)
+ this->buf[511] = 0;
+ else
+ *this->cursor = 0;
+ }
+ }
+private:
+ const char *username;
+ const char *password;
+ int is_btpro_server;
+
+ NetworkHTTPContentConnecter *conn;
+ char buf[512];
+ char *cursor;
+};
+
+static BTProAccountManager accmgr ("Username", "Password");
+
/**
* Send an actual chat message.
* @param buf The message to send.
@@ -277,7 +372,29 @@
{
if (StrEmpty(buf)) return;
if (!_network_server) {
- MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
+ const char *p = buf;
+
+ // just making sure it has been called
+ accmgr.onServerConnectHandler();
+
+ if ( !accmgr.isBTProServer() )
+ MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
+ else {
+ while (isspace(*p))
+ p++;
+ if (!p || !*p );
+ else if (*p != '!')
+ MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
+ else {
+ p++;
+ if ( strcasecmp(p, "login") )
+ MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
+ else {
+ // hijack the !login command
+ accmgr.initiateLoginSequence();
+ }
+ }
+ }
} else {
NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
}
////////////////////////////
Nevertheless if you want to make the client portable, you have more than wininet to fix. ShellAPI is used to open browser on forum URL, while OpenTTD already offers the portable:
void OSOpenBrowser(const char *url);
The function is not declared in any header file but you can locally declare it using an "extern" prior calling it...
extern void OSOpenBrowser(const char *url);
have fun && good luck
Blup
EDIT:
btw, if anybody compile it as is and it doesn't work, don't complain to me. I don't have any free time available for openttd atm... maybe in fall.