Skip to content

Commit

Permalink
Merge branch 'bugfixes'
Browse files Browse the repository at this point in the history
* bugfixes:
  Check if we actually need to hide widgets before hiding them
  Fix player counts for both AI & humans & 'closed' slots in MP games
  Should fix indicator for loading, skirmish & MP screens. fixes ticket:3104
  Fix calling batch file for autorevision.sh script refs: 1759623
  Don't go past the map's player limits when allocating players. fixes ticket:3089
  Fix issues that were overlooked from the revert(s) in ac550ac
  qtscript: Add a note about local variables to the documentation.
  Splice in the Changelog from 2.3.
  Set radarOnScreen to true by default.
  Add general rules script for the campaign.
  Run eventStartLevel always, not only for skirmish.
  • Loading branch information
cybersphinx committed Feb 4, 2012
2 parents 0b1fbf7 + 9185340 commit 73ec38c
Show file tree
Hide file tree
Showing 10 changed files with 1,058 additions and 72 deletions.
947 changes: 935 additions & 12 deletions ChangeLog

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions build_tools/autorevision.bat
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
echo "Building autorevision.h... (msysgit must be in system path)"
IF EXIST %1..\src\autorevision.h del %1..\src\autorevision.h
sh.exe %1..\build_tools\autorevision.sh %1..\src\autorevision.h.lf
IF NOT EXIST %1..\src\autorevision.h.lf goto failed:
cd %1..\
echo %1
echo %cd%
IF EXIST autorevision.h del autorevision.h
sh.exe %1..\build_tools\autorevision.sh src\autorevision.h.lf
IF NOT EXIST src\autorevision.h.lf goto failed:
echo "converting file to CRLF from LF"
perl -p -e 's/\n/\r\n/' < %1..\src\autorevision.h.lf > %1..\src\autorevision.h
del %1..\src\autorevision.h.lf
IF EXIST %1..\src\autorevision.h goto good:
perl -p -e 's/\n/\r\n/' < src\autorevision.h.lf > src\autorevision.h
del src\autorevision.h.lf
IF EXIST src\autorevision.h goto good:
:failed
echo "Failed! Is msysgit in your system path?"
exit
Expand Down
37 changes: 37 additions & 0 deletions data/base/script/rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// General rules for the campaign
//
// * Enable unit design and minimap only when an HQ exists

function eventStartLevel()
{
// Disable by default
setMiniMap(false);
setDesign(false);

var structlist = enumStruct(me);
for (var i = 0; i < structlist.length; i++)
{
// Simulate build events to enable minimap/unit design when an HQ exists
eventStructureBuilt(structlist[i]);
}
}

function eventStructureBuilt(struct)
{
if (struct.player == selectedPlayer && struct.type == STRUCTURE && struct.stattype == HQ)
{
// Enable unit design and minimap when an HQ gets built
setMiniMap(true);
setDesign(true);
}
}

function eventDestroyed(victim)
{
if (victim.player == selectedPlayer && victim.type == STRUCTURE && victim.stattype == HQ)
{
// Disable unit design and minimap when the HQ gets destroyed
setMiniMap(false);
setDesign(false);
}
}
3 changes: 3 additions & 0 deletions data/base/wrf/basic.wrf
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,6 @@ file ANI "cybdpjmp.ani"
file ANI "cybdplnd.ani"
file ANI "cybdprun.ani"
file ANIMCFG "anim.cfg"

directory "script"
file JAVASCRIPT "rules.js"
3 changes: 2 additions & 1 deletion doc/javascript.tex
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ \subsection{Global objects}

All variables stored on global (in global scope) are stored when the game is saved, and restored when it is
loaded. However, this may not work properly for complex objects. Basic arrays and basic types are supported,
but it is generally not recommended to put objects on global, even though simple ones may work.
but it is generally not recommended to put objects on global, even though simple ones may work. Since the game
can't be saved while a function is running, you don't need to worry about local variables.

Const definitions are not stored in savegames, and are therefore recommended over variables to hold information
that does not change.
Expand Down
95 changes: 59 additions & 36 deletions lib/netplay/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void NETallowJoining(void);
static void recvDebugSync(NETQUEUE queue);
static bool onBanList(const char *ip);
static void addToBanList(const char *ip, const char *name);

static void NETfixPlayerCount(void);
/*
* Network globals, these are part of the new network API
*/
Expand Down Expand Up @@ -165,7 +165,7 @@ unsigned NET_PlayerConnectionStatus[CONNECTIONSTATUS_NORMAL][MAX_PLAYERS];
**/
static char const *versionString = version_getVersionString();
static int NETCODE_VERSION_MAJOR = 6;
static int NETCODE_VERSION_MINOR = 3;
static int NETCODE_VERSION_MINOR = 4;

bool NETisCorrectVersion(uint32_t game_version_major, uint32_t game_version_minor)
{
Expand Down Expand Up @@ -365,7 +365,8 @@ static signed int NET_CreatePlayer(const char* name)
{
signed int index;

for (index = 0; index < MAX_CONNECTED_PLAYERS; index++)
// only look for spots up to the max players allowed on the map
for (index = 0; index < gamestruct.desc.dwMaxPlayers; index++)
{
if (NetPlay.players[index].allocated == false && NetPlay.players[index].ai == AI_OPEN)
{
Expand Down Expand Up @@ -1654,6 +1655,7 @@ bool NETrecvNet(NETQUEUE *queue, uint8_t *type)

if (NetPlay.isHost)
{
NETfixPlayerCount();
NETallowJoining();
}

Expand Down Expand Up @@ -2103,13 +2105,34 @@ static void NETregisterServer(int state)
}
}

// ////////////////////////////////////////////////////////////////////////
// Check player "slots" & update player count if needed.
void NETfixPlayerCount(void)
{
int playercount = 0;

for (int index = 0; index < gamestruct.desc.dwMaxPlayers; index++)
{
if ((NetPlay.players[index].allocated == false && NetPlay.players[index].ai != AI_OPEN) || NetPlay.players[index].allocated)
{
playercount++;
}
}

if (allow_joining && NetPlay.isHost && NetPlay.playercount != playercount)
{
debug(LOG_NET,"Updating player count from %d to %d", (int)NetPlay.playercount, playercount);
gamestruct.desc.dwCurrentPlayers = NetPlay.playercount = playercount;
NETregisterServer(WZ_SERVER_UPDATE);
}

}
// ////////////////////////////////////////////////////////////////////////
// Host a game with a given name and player name. & 4 user game flags
static void NETallowJoining(void)
{
unsigned int i;
char buffer[6] = {'\0'};
char buffer[10] = {'\0'};
char* p_buffer;
int32_t result;
bool connectFailed = true;
Expand Down Expand Up @@ -2168,54 +2191,54 @@ static void NETallowJoining(void)
// and have no data waiting.
if (checkSockets(tmp_socket_set, NET_TIMEOUT_DELAY) > 0
&& socketReadReady(tmp_socket[i])
&& (recv_result = readNoInt(tmp_socket[i], p_buffer, 5))
&& (recv_result = readNoInt(tmp_socket[i], p_buffer, 8))
&& recv_result != SOCKET_ERROR)
{
// A 2.3.7 client sends a "list" command first,
// we just close the socket so he sees a "Connection Error".
// A 2.3.7 client sends a "list" command first, just drop the connection.
if (strcmp(buffer, "list") == 0)
{
debug(LOG_ERROR, "An old client tried to connect, closing the socket.");
debug(LOG_INFO, "An old client tried to connect, closing the socket.");
connectFailed = true;
}
else
{
// New clients send NETCODE_VERSION_MAJOR and NETCODE_VERSION_MINOR
// Check these numbers with our own.

// Read another 3 bytes into the buffer
p_buffer += 5;
memcpy(&major, p_buffer, sizeof(int32_t));
major = ntohl(major);
p_buffer += sizeof(int32_t);
memcpy(&minor, p_buffer, sizeof(int32_t));
minor = ntohl(minor);

if (readNoInt(tmp_socket[i], p_buffer, 3) != SOCKET_ERROR)
if (NETisCorrectVersion(major, minor))
{
p_buffer = buffer;
memcpy(&major, p_buffer, sizeof(int32_t));
major = ntohl(major);
p_buffer += sizeof(uint32_t);
memcpy(&minor, p_buffer, sizeof(int32_t));
minor = ntohl(minor);

if (NETisCorrectVersion(major, minor))
{
result = htonl(ERROR_NOERROR);
memcpy(&buffer, &result, sizeof(result));
writeAll(tmp_socket[i], &buffer, sizeof(result));
socketBeginCompression(tmp_socket[i]);
result = htonl(ERROR_NOERROR);
memcpy(&buffer, &result, sizeof(result));
writeAll(tmp_socket[i], &buffer, sizeof(result));
socketBeginCompression(tmp_socket[i]);

// Connection is successful.
connectFailed = false;
}
else
{
// Commented out as each masterserver check creates an error.
debug(LOG_ERROR, "Received an invalid version \"%d.%d\".", major, minor);
result = htonl(ERROR_WRONGVERSION);
memcpy(&buffer, &result, sizeof(result));
writeAll(tmp_socket[i], &buffer, sizeof(result));
}
// Connection is successful.
connectFailed = false;
}
else
{
debug(LOG_NET, "Socket error while reading clients version.");
// Commented out as each masterserver check creates an error.
debug(LOG_ERROR, "Received an invalid version \"%d.%d\".", major, minor);
result = htonl(ERROR_WRONGVERSION);
memcpy(&buffer, &result, sizeof(result));
writeAll(tmp_socket[i], &buffer, sizeof(result));
}
if ((int)NetPlay.playercount == gamestruct.desc.dwMaxPlayers)
{
// early player count test, in case they happen to get in before updates.
// Tell the player that we are full.
uint8_t rejected = ERROR_FULL;
NETbeginEncode(NETnetTmpQueue(i), NET_REJECTED);
NETuint8_t(&rejected);
NETend();
NETflush();
connectFailed = true;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/display3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ SDWORD mouseTileX, mouseTileY;
Vector2i mousePos(0, 0);

/// Do we want the radar to be rendered
bool radarOnScreen=false;
bool radarOnScreen = true;
bool radarPermitted = true;

/// Show unit/building gun/sensor range
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,7 @@ static bool gameLoad(const char* fileName)
// Failure to open the file is a failure to load the specified savegame
return true;
}

initLoadingScreen(true);
debug(LOG_WZ, "gameLoad");

// Read the header from the file
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,8 @@ static void startGameLoop(void)
if (game.type == SKIRMISH)
{
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_START_NEXT_LEVEL);
triggerEvent(TRIGGER_START_LEVEL);
}
triggerEvent(TRIGGER_START_LEVEL);
screen_disableMapPreview();
}

Expand Down Expand Up @@ -878,6 +878,7 @@ static bool initSaveGameLoad(void)
}

screen_StopBackDrop();
closeLoadingScreen();

// Trap the cursor if cursor snapping is enabled
if (war_GetTrapCursor())
Expand Down
23 changes: 9 additions & 14 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@

#include "init.h"
#include "levels.h"
#include "wrappers.h"

#define MAP_PREVIEW_DISPLAY_TIME 2500 // number of milliseconds to show map in preview

Expand Down Expand Up @@ -1251,11 +1252,11 @@ static void hidePasswordForm(void)
{
EnablePasswordPrompt = false;

widgHide(psWScreen, FRONTEND_PASSWORDFORM);
widgHide(psWScreen, CON_PASSWORD_LABEL);
widgHide(psWScreen, CON_PASSWORD);
widgHide(psWScreen, CON_PASSWORDYES);
widgHide(psWScreen, CON_PASSWORDNO);
if (widgGetFromID(psWScreen, FRONTEND_PASSWORDFORM)) widgHide(psWScreen, FRONTEND_PASSWORDFORM);
if (widgGetFromID(psWScreen, CON_PASSWORD_LABEL)) widgHide(psWScreen, CON_PASSWORD_LABEL);
if (widgGetFromID(psWScreen, CON_PASSWORD)) widgHide(psWScreen, CON_PASSWORD);
if (widgGetFromID(psWScreen, CON_PASSWORDYES))widgHide(psWScreen, CON_PASSWORDYES);
if (widgGetFromID(psWScreen, CON_PASSWORDNO)) widgHide(psWScreen, CON_PASSWORDNO);

widgReveal(psWScreen, FRONTEND_SIDETEXT);
widgReveal(psWScreen, FRONTEND_BOTFORM);
Expand Down Expand Up @@ -2602,14 +2603,8 @@ static void stopJoining(void)
NetPlay.isHost = false;
}

if(NetPlay.bComms) // not even connected.
{
changeTitleMode(GAMEFIND);
}
else
{
changeTitleMode(MULTI);
}
changeTitleMode(MULTI);

selectedPlayer = 0;
realSelectedPlayer = 0;
return;
Expand Down Expand Up @@ -3120,7 +3115,7 @@ void startMultiplayerGame(void)
bMultiPlayer = true;
bMultiMessages = true;
NETsetPlayerConnectionStatus(CONNECTIONSTATUS_NORMAL, NET_ALL_PLAYERS); // reset disconnect conditions

initLoadingScreen(true);
if (NetPlay.isHost)
{
// This sets the limits to whatever the defaults are for the limiter screen
Expand Down

0 comments on commit 73ec38c

Please sign in to comment.