(svn r1239) -Feature: Added gui option of setting company password. It can be found in the 'company information' window

-Spiced up 'set company_pw' a bit, where if no pw is typed, it shows the current one.
-Added a space between company name and player; looks better
This commit is contained in:
darkvater 2004-12-22 23:24:53 +00:00
parent 0e3399177e
commit c4836bbd70
24 changed files with 99 additions and 56 deletions

View File

@ -682,17 +682,11 @@ DEF_CONSOLE_CMD(ConSet) {
return NULL;
}
if (argc == 3) {
if (strncmp(argv[2], "*", NETWORK_PASSWORD_LENGTH) == 0) {
_network_player_info[_local_player].password[0] = '\0';
NetworkChangeCompanyPassword(argv[2]);
} else {
ttd_strlcpy(_network_player_info[_local_player].password, argv[2], sizeof(_network_player_info[_local_player].password));
}
if (!_network_server)
SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
IConsolePrintF(_iconsole_color_warning, "Company protected with '%s'", _network_player_info[_local_player].password);
} else {
IConsolePrint(_iconsole_color_default, "'set company_pw' sets a password on your company, so no-one without the correct password can join.");
IConsolePrint(_iconsole_color_default, "'set company_pw' sets a password for your company, so no-one without the correct password can join.");
IConsolePrint(_iconsole_color_warning, "Usage: set company_pw \"<password>\". Use * as <password> to set no password.");
IConsolePrintF(_iconsole_color_warning, "Current password is: '%s'", _network_player_info[_local_player].password);
}
return NULL;
}

View File

@ -2071,6 +2071,9 @@ STR_RELOCATE_COMPANY_HEADQUARTERS :{BLACK}Rebuild company headquarters elsewh
STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS :{WHITE}Can't build company headquarters...
STR_7072_VIEW_HQ :{BLACK}View HQ
STR_RELOCATE_HQ :{BLACK}Relocate HQ
STR_COMPANY_PASSWORD :{BLACK}Password
STR_COMPANY_PASSWORD_TOOLTIP :{BLACK}Password-protect your company to prevent unauthorised users from joining. Use '*' to empty password.
STR_SET_COMPANY_PASSWORD :Set company password
STR_7073_WORLD_RECESSION_FINANCIAL :{BIGFONT}{BLACK}World Recession!{}{}Financial experts fear worst as economy slumps!
STR_7074_RECESSION_OVER_UPTURN_IN :{BIGFONT}{BLACK}Recession Over!{}{}Upturn in trade gives confidence to industries as economy strengthens!
STR_7075_TOGGLE_LARGE_SMALL_WINDOW :{BLACK}Toggle large/small window size

View File

@ -1360,6 +1360,20 @@ void NetworkShutDown(void)
#endif
}
void NetworkChangeCompanyPassword(const char *str)
{
if (strncmp(str, "*", sizeof(_network_player_info[_local_player].password)) == 0) {
_network_player_info[_local_player].password[0] = '\0';
IConsolePrint(_iconsole_color_warning, "Company password protection removed.");
} else {
ttd_strlcpy(_network_player_info[_local_player].password, str, sizeof(_network_player_info[_local_player].password));
IConsolePrintF(_iconsole_color_warning, "Company protected with password '%s'.", _network_player_info[_local_player].password);
}
if (!_network_server)
SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
}
#else
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string) {}

View File

@ -200,5 +200,6 @@ void NetworkUpdateClientInfo(uint16 client_index);
void NetworkAddServer(const byte *b);
void NetworkRebuildHostList();
NetworkGameList *NetworkQueryServer(const byte* host, unsigned short port, bool game_info);
void NetworkChangeCompanyPassword(const char *str);
#endif /* NETWORK_H */

View File

@ -13,7 +13,7 @@
# include <winsock2.h>
# include <ws2tcpip.h>
# pragma comment (lib, "ws2_32.lib")
# define ENABLE_NETWORK // On windows, the network is always enabled
//# define ENABLE_NETWORK // On windows, the network is always enabled
# define GET_LAST_ERROR() WSAGetLastError()
# define EWOULDBLOCK WSAEWOULDBLOCK
// Windows has some different names for some types..

View File

@ -9,6 +9,12 @@
#include "command.h"
#include "vehicle.h"
#include "economy.h"
#include "network.h"
#ifdef ENABLE_NETWORK
#include "network_data.h"
#include "network_client.h"
#endif
static void DoShowPlayerFinances(int player, bool small);
@ -357,6 +363,8 @@ static const Widget _my_player_company_widgets[] = {
{ WWT_PUSHTXTBTN, 14, 180, 269, 158, 169, STR_7009_PRESIDENT_NAME, STR_7032_CHANGE_THE_PRESIDENT_S},
{ WWT_PUSHTXTBTN, 14, 270, 359, 158, 169, STR_7008_COMPANY_NAME, STR_7033_CHANGE_THE_COMPANY_NAME},
{ WWT_PUSHTXTBTN, 14, 266, 355, 18, 29, STR_706F_BUILD_HQ, STR_7070_BUILD_COMPANY_HEADQUARTERS},
{ WWT_EMPTY, 14, 266, 355, 32, 43, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, 14, 266, 355, 138, 149, STR_COMPANY_PASSWORD, STR_COMPANY_PASSWORD_TOOLTIP},
{ WIDGETS_END},
};
@ -385,6 +393,7 @@ static const Widget _my_player_company_bh_widgets[] = {
{ WWT_PUSHTXTBTN, 14, 270, 359, 158, 169, STR_7008_COMPANY_NAME, STR_7033_CHANGE_THE_COMPANY_NAME},
{ WWT_PUSHTXTBTN, 14, 266, 355, 18, 29, STR_7072_VIEW_HQ, STR_7070_BUILD_COMPANY_HEADQUARTERS},
{ WWT_PUSHTXTBTN, 14, 266, 355, 32, 43, STR_RELOCATE_HQ, STR_RELOCATE_COMPANY_HEADQUARTERS},
{ WWT_PUSHTXTBTN, 14, 266, 355, 138, 149, STR_COMPANY_PASSWORD, STR_COMPANY_PASSWORD_TOOLTIP},
{ WIDGETS_END},
};
@ -481,8 +490,10 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
Player *p = DEREF_PLAYER(w->window_number);
uint32 dis;
if (w->widget != _other_player_company_widgets)
if (w->widget != _other_player_company_widgets) {
w->widget = (p->location_of_house != 0) ? _my_player_company_bh_widgets : _my_player_company_widgets;
if (!_networking) w->hidden_state |= (1 << 9); // hide company-password widget
}
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
@ -569,9 +580,19 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
SetObjectToPlaceWnd(0x2D0, 1, w);
SetTileSelectSize(2, 2);
break;
case 9: /* buy 25% */
case 9: {/* buy 25% or password protect your company */
#ifdef ENABLE_NETWORK
if (w->widget != _other_player_company_widgets) {
StringID str;
WP(w,def_d).byte_1 = 2;
str = AllocateName(_network_player_info[_local_player].password, 0);
ShowQueryString(str, STR_SET_COMPANY_PASSWORD, sizeof(_network_player_info[_local_player].password), 250, w->window_class, w->window_number);
DeleteName(str);
} else
#endif
DoCommandP(0, w->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
break;
} break;
case 10: /* sell 25% */
DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
@ -600,14 +621,24 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: {
byte *b = e->edittext.str;
if (*b == 0)
char *b = (char*)e->edittext.str;
if (*b == 0 && WP(w,def_d).byte_1 != 2) // empty string is allowed for password
return;
memcpy(_decode_parameters, b, 32);
if (WP(w,def_d).byte_1) {
DoCommandP(0, w->window_number, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
} else {
switch (WP(w,def_d).byte_1) {
case 0: /* Change president name */
DoCommandP(0, w->window_number, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
break;
case 1: /* Change company name */
DoCommandP(0, w->window_number, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
break;
#ifdef ENABLE_NETWORK
case 2: /* Change company password */
if (*b == 0) *b = '*'; // empty password is a '*' because of console argument
NetworkChangeCompanyPassword(b);
#endif
}
} break;