Lobby system

Previous topic - Next topic

MrTAToad

Here is my Lobby system code.  Its not finished yet, but it does work.  It makes heavy use of DDGui

Here is the test code :

Code (glbasic) Select
// --------------------------------- //
// Project: TestLobby
// Start: Friday, October 02, 2009
// IDE Version: 7.115
TYPE tPlayer
x%
y%
ENDTYPE

GLOBAL player AS tPlayer
GLOBAL lobbyz AS tNetworkSystem
LOCAL host$
LOCAL doHost%
LOCAL mx%,my%,b1%,b2%,newX%,newY%
LOCAL sendTime

DEBUG GETCOMMANDLINE$()+"\n"

INPUT host$,100,100
IF host$="h" OR host$="H"
doHost%=TRUE
ELSE
doHost%=FALSE
ENDIF

IF initialiseLobbySystem(lobbyz,doHost%,"HostPlayer",1,TRUE)=FALSE
DEBUG "Sock error"
END
ENDIF

newX%=100
newY%=100
sendTime=0.0
WHILE TRUE
IF processLobby(lobbyz)=LOBBY_CANCELLED%
END
ELSEIF lobbyz.state%=STATE_INGAME%
DEBUG "Player ID : "+lobbyz.playerID%+"\n"

IF lobbyz.message.isMessage%=TRUE
SELECT lobbyz.message.basicMessage.messageNum%
CASE MESSAGE_USERDATA%
DEBUG "Player ID received : "+lobbyz.message.message$[0]+"\n"
IF INTEGER(lobbyz.message.message$[0])=lobbyz.playerID%
newX%=INTEGER(lobbyz.message.message$[1])
newY%=INTEGER(lobbyz.message.message$[2])
ELSE
player.x%=INTEGER(lobbyz.message.message$[1])
player.y%=INTEGER(lobbyz.message.message$[2])
ENDIF


ENDSELECT
ENDIF

DRAWRECT newX%,newY%,32,32,RGB(100,100,255)
DRAWRECT player.x%,player.y%,32,32,RGB(255,255,0)

MOUSESTATE mx%,my%,b1%,b2%
IF (mx%<>newX% OR my%<>newY%) AND GETTIMERALL()>=sendTime
sendPlayerData(lobbyz,INTEGER(mx%)+","+INTEGER(my%))
sendTime=GETTIMERALL()+500.0
ENDIF
ENDIF

SHOWSCREEN
WEND


String routines :

Code (glbasic) Select
FUNCTION RIGHT$:str$,length%
RETURN MID$(str$, MAX(0, LEN(str$)-length%), length%)
ENDFUNCTION

FUNCTION LEFT$:str$,length%
RETURN MID$(str$,0,length%)
ENDFUNCTION


And the main lobby code has to be included as its too large to fit in the message length

[attachment deleted by admin]