Welcome, Guest
Username: Password: Remember me

TOPIC:

Re: BTPro Client Suggestions 10 years 9 months ago #1834

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.

Please Log in or Create an account to join the conversation.

Last edit: by Blup. Reason: bletch

Re: BTPro Client Suggestions 10 years 9 months ago #1835

hello :)

Thanks Blup. Actually the version I had prepared it's quite similar and was tested on linux and mac OS's. Somehow (maybe lazyness) I've worked on the wininet based one :D
Anyway, good or bad, it worked and probably today I'll have the time to make it for 1.3.1.

take care :)
  • ST2
  • ST2's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1222
  • Thank you received: 628

Please Log in or Create an account to join the conversation.

Re: BTPro Client Suggestions 10 years 9 months ago #1844

new public version released, now compatible with all OS's (I think ^^)

available here , already compiled for Windows versions, diff file included to who what's to build it in other OS's.

It's a modified OpenTTD version so, any bugs please report them here.

good games all :)
  • ST2
  • ST2's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1222
  • Thank you received: 628

Please Log in or Create an account to join the conversation.

BTPro Client Suggestions 10 years 8 months ago #1957

In the new version brought out yesterday, I miss the exact town rating, which used to be next to the name of the town, so you could see how good or bad your company was doing in the town, which was more exact than those 7 or 8 different levels. I liked it, especially for the CB servers. Is there a reason why it is gone?
  • vGelder
  • vGelder's Avatar
  • Offline
  • BTPro RETIRED Moderator
  • BTPro RETIRED Moderator
  • Posts: 221
  • Thank you received: 55

Please Log in or Create an account to join the conversation.

BTPro Client Suggestions 10 years 8 months ago #1962

hi :)

yes, there was a particular reason why was removed... I'll explain:
- while trying to fix the tooltips bug I've disabled it... when fixed... forgot to put it there again :D

It's done and thanks for noticing :)
  • ST2
  • ST2's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1222
  • Thank you received: 628

Please Log in or Create an account to join the conversation.

BTPro Client Suggestions 10 years 7 months ago #2017

well, I was thinking on add the Show vehicles in tunnels patch on cliente but no idea how can be usefull...

what do you all think?

meanwhile... enjoy the games and have fun :)
  • ST2
  • ST2's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1222
  • Thank you received: 628

Please Log in or Create an account to join the conversation.

Time to create page: 0.033 seconds
Best hosting deal on hostgator coupon or play poker on party poker
Copyright 2020 BTPro Client Suggestions - Page 4 - BTPro - OpenTTD Community.