git repos / blockattack-game

commit 43765588

sago007 · 2012-05-16 19:14
43765588a0821691788eb24d776bbac669617ee3 patch · browse files
parent 6710d462270fbe4f196b8a85a1c04be12ac671af

The network system does now connect but still needs lots of changes to be playable again


git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@152 9d7177f8-192b-0410-8f35-a16a89829b06

Changed files

M source/code/BlockGame.cpp before
M source/code/NetworkThing.hpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index d795dda..f649aca 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -2097,7 +2097,7 @@ void BlockGame::Update(int newtick)
/*cout << "Testing " << replayIndex << "<" << theReplay.getActions().size()
<< " && " << theReplay.getActions().at(replayIndex).time << "<=" <<
newtick-gameStartedAt << endl;*/
- while(replayIndex < theReplay.getActions().size() &&
+ while(replayIndex >= 0 && replayIndex < theReplay.getActions().size() &&
theReplay.getActions().at(replayIndex).time <= newtick-gameStartedAt)
{
Action a = theReplay.getActions().at(replayIndex);
@@ -2122,7 +2122,7 @@ void BlockGame::ActionPerformed(int action, string param)
int BlockGame::GotAction(Sint32 &tick,int &action,string &param)
{
if(actionIndex < theReplay.getActions().size()) {
- Action a = theReplay.getActions().at(replayIndex);
+ Action a = theReplay.getActions().at(actionIndex);
tick = a.time;
action = a.action;
param = a.param;
diff --git a/source/code/NetworkThing.hpp b/source/code/NetworkThing.hpp index 95740cf..473bd3c 100644 --- a/source/code/NetworkThing.hpp +++ b/source/code/NetworkThing.hpp
@@ -131,7 +131,7 @@ public:
address.host = ENET_HOST_ANY;
/* Bind the server to port SERVERPORT. */
- address.port = SERVERPORT;
+ address.port = Config::getInstance()->getInt("portv4");
server = enet_host_create (& address /* the address to bind the server host to */,
1 /* allow up to 1 clients and/or outgoing connections */,
@@ -160,7 +160,7 @@ public:
ENetEvent event;
enet_address_set_host (& address, server.c_str());
- address.port = SERVERPORT;
+ address.port = Config::getInstance()->getInt("portv4");
ntDisconnect();
client = enet_host_create (NULL /* create a client host */,
@@ -193,7 +193,7 @@ public:
}
else
{
- cout << "Server didn't answer in time" << endl;
+ cout << "Server " << server.c_str() << ":" << address.port << " didn't answer in time" << endl;
}
}
}
@@ -294,7 +294,7 @@ public:
ENetPacket * namePacket = enet_packet_create(bgHome->name,sizeof(char[30]),ENET_PACKET_FLAG_RELIABLE);
//if(weAreAServer)
enet_host_broadcast (server, 3, namePacket);
- ENetPacket * answerPacket = enet_packet_create("version3",sizeof("version3"),ENET_PACKET_FLAG_RELIABLE);
+ ENetPacket * answerPacket = enet_packet_create("version4",sizeof("version4"),ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast (server, 3, answerPacket);
theSeed = time(0)/4;
bgHome->putStartBlocks(theSeed);
diff --git a/source/code/main.cpp b/source/code/main.cpp index 627244a..66dab4d 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -3029,7 +3029,7 @@ void changePuzzleLevels()
static BlockGameSdl *player1;
static BlockGameSdl *player2;
-void StartSinglePlayerEndless()
+static void StartSinglePlayerEndless()
{
//1 player - endless
player1->NewGame(50,100,SDL_GetTicks());
@@ -3043,7 +3043,7 @@ void StartSinglePlayerEndless()
strcpy(player2->name, player2name);
}
-void StartSinglePlayerTimeTrial()
+static void StartSinglePlayerTimeTrial()
{
player1->NewTimeTrialGame(50,100,SDL_GetTicks());
closeAllMenus();
@@ -3055,7 +3055,7 @@ void StartSinglePlayerTimeTrial()
strcpy(player2->name, player2name);
}
-int StartSinglePlayerPuzzle(int level)
+static int StartSinglePlayerPuzzle(int level)
{
int myLevel = PuzzleLevelSelect(0);
if(myLevel == -1)
@@ -3074,7 +3074,7 @@ int StartSinglePlayerPuzzle(int level)
}
-void StarTwoPlayerTimeTrial()
+static void StarTwoPlayerTimeTrial()
{
player1->NewTimeTrialGame(50,100,SDL_GetTicks());
player2->NewTimeTrialGame(xsize-500,100,SDL_GetTicks());
@@ -3095,7 +3095,7 @@ void StarTwoPlayerTimeTrial()
strcpy(player2->name, player2name);
}
-void StartTwoPlayerVs()
+static void StartTwoPlayerVs()
{
//2 player - VsMode
player1->NewVsGame(50,100,player2,SDL_GetTicks());
@@ -3119,25 +3119,26 @@ void StartTwoPlayerVs()
strcpy(player2->name, player2name);
}
-void StartReplay(string filename)
+static void StartReplay(string filename)
{
Replay r1;
r1.loadReplay(filename);
player1->playReplay(50,100,SDL_GetTicks(),r1);
}
-void StartHostServer()
+static void StartHostServer()
{
player1->SetGameOver();
player2->SetGameOver();
nt.startServer();
}
-void StartJoinServer()
+static void StartJoinServer()
{
player1->SetGameOver();
player2->SetGameOver();
- nt.connectToServer(Config::getInstance()->getString("address0"));
+ string server = Config::getInstance()->getString("address0");
+ nt.connectToServer(server.substr(0,server.find(" ")));
}