Okay man, thanks. Though just as a bit of forewarning, all the current code changed was that the host polls to check for the first message "Player2 Joined The Game" from player 2, then sends a message back saying request accepted. However, I think I explained it in the previous post what happened with that, so that may have broke the code even further.
EDIT: I tried doing what you said earlier, which was instead of checking for a initiating packet, checking for new connections...
It's weird... it joins, but then both players act like clients and each is controlling paddle 2, with no interaction between each other.
Here's the code if you want it:
Rem Project: Internet Pong (Final version will be for 20 line challenge).
Rem Created: Friday, September 23, 2011 By DarthRhyno
Rem ***** Main Source File *****
SET DISPLAY MODE 640, 480, 32
TYPE Player
y AS DWORD
score AS DWORD
ping AS DWORD
ENDTYPE
TYPE MyBall
x AS INTEGER
y AS INTEGER
x_dir AS INTEGER
y_dir AS INTEGER
ENDTYPE
player1 AS Player
player2 AS Player
player1.y = 239
player2.y = 239
player1.score = 0
player2.score = 0
ball AS MyBall
ball.x = 319
ball.y = 239
ball.x_dir = 1
ball.y_dir = -1
choice = 0
// Select connection type
PERFORM CHECKLIST FOR NET CONNECTIONS
SLEEP 100
connection_selection = 0
total_connections = CHECKLIST QUANTITY()
FOR i = 1 TO total_connections
PRINT CHECKLIST STRING$(i)
IF COMPARE CASE$(CHECKLIST STRING$(i), "Internet TCP/IP Connection For DirectPlay") = 1 THEN connection_selection = i
NEXT
PRINT "Connection selection is ", connection_selection, "."
WAIT KEY
// Figure out what you are (host/player)
CLEAR ENTRY BUFFER
REPEAT
CLS
c$ = ENTRY$(1)
TEXT 0,0, "Press 1 to Host a game/Press 2 to Join a game: "+c$
IF (RETURNKEY() = 1)
IF ((COMPARE CASE$(c$, "1") = 1) OR (COMPARE CASE$(c$, "2") = 1))
choice = INT(VAL(c$))
ENDIF
ENDIF
UNTIL choice <> 0
CLS
// If person is host
IF choice = 1
//PRINT "Enter your IP address in the prompt."
SET NET CONNECTION connection_selection, "192.168.1.113" `"38.102.24.113" // Insert your IP here
CREATE NET GAME "OssumPong", "Player1", 2, 1
GOSUB _wait_for_player2
GOSUB _start_game
GOSUB _main_loop_host
// If person is client
ELSE
//PRINT "Enter the host IP address in the prompt."
SET NET CONNECTION connection_selection, "192.168.1.113" `"38.102.24.113" // Insert host IP here
PERFORM CHECKLIST FOR NET SESSIONS
IF CHECKLIST QUANTITY() < 1
PRINT "No games available."
ELSE
game$ = CHECKLIST STRING$(1)
PRINT "JOINING GAME: ", game$, "."
JOIN NET GAME 1, "Player2"
GOSUB _start_game
GOSUB _main_loop_client
ENDIF
ENDIF
WAIT KEY
_wait_for_player2:
waiting_for_players = 1
REPEAT
PERFORM CHECKLIST FOR NET PLAYERS
SET CURSOR 0,0
PRINT "Waiting for player 2... waiting for players =", waiting_for_players
IF checklist quantity() > 1 THEN waiting_for_players = 0
UNTIL waiting_for_players = 0
RETURN
_start_game:
SYNC ON
SYNC RATE 60
SET CURRENT BITMAP 0
// CREATE SPRITES FOR GAME
INK RGB(0,255,0), RGB(0,0,0)
BOX 0,0,10,50
GET IMAGE 1, 0,0,10,50
SPRITE 1, 0, 239, 1
SPRITE 2, 630, 239, 1
CLS
INK RGB(0,0,255), RGB(0,0,0)
CIRCLE 5, 5, 5
GET IMAGE 2, 0,0,11,11
SPRITE 3, 319, 239, 2
Return
// Main Loop Host
_main_loop_host:
ball_timer = TIMER()
ping_rate = 250
my_time = TIMER()
DO
// Get Packets First
GOSUB _host_send_recv_packets
CLS
// Update Sprites
SPRITE 1, 0, player1.y, 1
SPRITE 2, 630, player2.y, 1
SPRITE 3, ball.x, ball.y, 2
INK RGB(255,255,255), RGB(0,0,0)
TEXT 0,0, "Player1 Score:"+Str$(player1.score)
TEXT (639-TEXT WIDTH("Player2 Score:"+Str$(player2.score))),0, "Player2 Score:"+Str$(player2.score)
// Gather Input
IF UPKEY() = 1
IF (player1.y > 0) THEN player1.y = player1.y - 1
ENDIF
IF DOWNKEY() = 1
IF (player1.y+50 < 479) THEN player1.y = player1.y + 1
ENDIF
// Increase ball position
GOSUB _increase_ball_position
// Rasterize everything
SYNC
LOOP
RETURN
_host_send_recv_packets:
WHILE (NET MESSAGE EXISTS() = 1)
GET NET MESSAGE
message$ = NET MESSAGE STRING$()
player2.y = INT(VAL(FIRST TOKEN$(message$, "*")))
player2.ping = VAL(NEXT TOKEN$("*"))
ping_rate = TIMER()-player2.ping
ENDWHILE
IF wait_for_player = 0
IF (TIMER() - my_time) >= ping_rate
my_time = TIMER()
my_message$ = Str$(player1.y)+"*"+Str$(ball.x)+"*"+Str$(ball.y)+"*"+Str$(player1.score)+"*"+Str$(player2.score)+Str$(my_time)
SEND NET MESSAGE STRING 0, my_message$
ENDIF
ENDIF
RETURN
_increase_ball_position:
ball.x = ball.x + ball.x_dir
ball.y = ball.y + ball.y_dir
IF ball.y < 0 THEN ball.y_dir = 1
IF ball.y > 479 THEN ball.y_dir = -1
IF SPRITE COLLISION(3, 2)=1 THEN ball.x_dir = -1
IF SPRITE COLLISION(3, 1)=1 THEN ball.x_dir = 1
IF ball.x < 0
player2.score = player2.score + 1
ball.x = 319
ball.y = 239
ENDIF
IF (ball.x + SPRITE WIDTH(3)) > 639
player1.score = player1.score + 1
ball.x = 319
ball.y = 239
ENDIF
// Main Loop Client
_main_loop_client:
DO
// Get Packets First
GOSUB _client_send_recv_packets
CLS
// Update Sprites
SPRITE 1, 0, player1.y, 1
SPRITE 2, 630, player2.y, 1
SPRITE 3, ball.x, ball.y, 2
INK RGB(255,255,255), RGB(0,0,0)
TEXT 0,0, "Player1 Score:"+Str$(player1.score)
TEXT (639-TEXT WIDTH("Player2 Score:"+Str$(player2.score))),0, "Player2 Score:"+Str$(player2.score)
// Gather Input
IF UPKEY() = 1
IF (player2.y > 0) THEN player2.y = player2.y - 1
ENDIF
IF DOWNKEY() = 1
IF (player2.y+50 < 479) THEN player2.y = player2.y + 1
ENDIF
SYNC
LOOP
RETURN
_client_send_recv_packets:
WHILE (NET MESSAGE EXISTS() = 1)
GET NET MESSAGE
message$ = NET MESSAGE STRING$()
player1.y = INT(VAL(FIRST TOKEN$(message$, "*")))
ball.x = INT(VAL(NEXT TOKEN$("*")))
ball.y = INT(VAL(NEXT TOKEN$("*")))
player1.score = INT(VAL(NEXT TOKEN$("*")))
player2.score = INT(VAL(NEXT TOKEN$("*")))
player1.ping = INT(VAL(NEXT TOKEN$("*")))
ENDWHILE
my_message$ = Str$(player2.y)+"*"+Str$(player1.ping)
SEND NET MESSAGE STRING 0, my_message$
RETURN
I just thought it was kind of peculiar.
In short, I got rid of the variable checking to see if it was waiting for a player, and put in another subroutine in front of the drawing routine and main loop. This subroutine loops, waiting to see if the amount of players is > 1, and if it is, continues on with the game. But as I said, then it hands everything over to (what appears to be) the client loop, even for the host side.
EDIT: I found out why the host acted like a client... I forgot to put in a "RETURN" at the end of _increase_ball_position. Also I left an unnecessary variable in from before. I'm going to retest it now. I retested it, and the good news is the host does what it's supposed to do, except it's not exchanging packets with the client. Neither one is updating the state for the other, which means the packets aren't going through correctly. I need to look at my packet routines in more depth it seems.