737 const char *player = NULL; |
737 const char *player = NULL; |
738 uint16 rport; |
738 uint16 rport; |
739 |
739 |
740 if (argc == 0) { |
740 if (argc == 0) { |
741 IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'"); |
741 IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'"); |
742 IConsoleHelp("IP can contain port and player: 'IP#Player:Port', eg: 'server.ottd.org#2:443'"); |
742 IConsoleHelp("IP can contain port and player: 'IP[[#Player]:Port]', eg: 'server.ottd.org#2:443'"); |
|
743 IConsoleHelp("Player #0 is new company, #255 is spectator all others are a certain company"); |
743 return true; |
744 return true; |
744 } |
745 } |
745 |
746 |
746 if (argc < 2) return false; |
747 if (argc < 2) return false; |
747 |
748 |
748 if (_networking) // We are in network-mode, first close it! |
749 if (_networking) // We are in network-mode, first close it! |
749 NetworkDisconnect(); |
750 NetworkDisconnect(); |
750 |
751 |
751 ip = argv[1]; |
752 ip = argv[1]; |
|
753 /* Default settings: default port and new company */ |
752 rport = NETWORK_DEFAULT_PORT; |
754 rport = NETWORK_DEFAULT_PORT; |
|
755 _network_playas = PLAYER_NEW_COMPANY; |
753 |
756 |
754 ParseConnectionString(&player, &port, ip); |
757 ParseConnectionString(&player, &port, ip); |
755 |
758 |
756 IConsolePrintF(_icolour_def, "Connecting to %s...", ip); |
759 IConsolePrintF(_icolour_def, "Connecting to %s...", ip); |
757 if (player != NULL) { |
760 if (player != NULL) { |
758 _network_playas = atoi(player); |
761 _network_playas = atoi(player); |
759 IConsolePrintF(_icolour_def, " player-no: %s", player); |
762 IConsolePrintF(_icolour_def, " player-no: %d", _network_playas); |
|
763 |
|
764 /* From a user pov 0 is a new player, internally it's different and all |
|
765 * players are offset by one to ease up on users (eg players 1-8 not 0-7) */ |
|
766 if (_network_playas == 0) _network_playas = PLAYER_NEW_COMPANY; |
|
767 if (!IsValidPlayer(_network_playas - 1) && |
|
768 (_network_playas != PLAYER_SPECTATOR && |
|
769 _network_playas != PLAYER_NEW_COMPANY)) { |
|
770 return false; |
|
771 } |
760 } |
772 } |
761 if (port != NULL) { |
773 if (port != NULL) { |
762 rport = atoi(port); |
774 rport = atoi(port); |
763 IConsolePrintF(_icolour_def, " port: %s", port); |
775 IConsolePrintF(_icolour_def, " port: %s", port); |
764 } |
776 } |