Game Programming and Development Tools

My simple network game – Xzider

Xzider

Junior Member

Posts: 2
From: USA
Registered: 04-03-2005
my code doesnt work, and cant figure out why > < ,

Server -


Graphics 800,600

ClsColor 0,0,100

Cls

Global Server

Global AcceptStream

Global P.Player

Global Message$

Global New_Id%


CreateServer(7000)


Type Player

Field Id%

Field Stream

Field Entity

Field Name$

Field x#

Field y#

Field z#

End Type


While Not KeyHit(1)

AcceptStream=AcceptTCPStream(Server)

If AcceptStream


P.Player=New Player

P\Stream=AcceptStream


P\Name$ = ReadString(P\Stream)

New_PID

P\Id%=New_Id%


WriteInt(P\Stream,P\Id%)

Print " Player " +P\Name$+ " has joined with PID% " + P\Id%
Send_BroadCast("New Player",1)


End If


For P.Player = Each Player

SendData

h=True

While h=True
Packet=ReadAvail(P\Stream)

If Packet>=2

Message$=ReadString(P\Stream)

MessageTypeS


Else


h=False

End If

Wend

Next

Wend

Delay 1

Function CreateServer(Port%)

Server=CreateTCPServer(Port%)


If Server<>0

Print "Server Established"

Else

Print "Server UnEstablished"

WaitKey

End

End If

Print "Listening On Port " + Port%

End Function

Function New_PID()
New_ID%=New_ID%+1
End Function

Function New_ID()
New_ID%=New_ID%+1
End Function


Function MessageTypeS()

Select Message$

Case "Cordinates XYZD"

For P.Player = Each Player

P\Name$=ReadString(p\Stream)

p\x#=ReadInt(p\Stream)

p\y#=ReadInt(p\Stream)


Print "XY " + p\x + " " + p\y


Next


End Select
End Function

Function SendData()
WriteString(p\Stream,"Cordinates XYZD")


WriteString(p\Stream,p\Name$)

WriteInt(p\Stream,p\x#)

WriteInt(p\Stream,p\y#)


End Function


Function Send_BroadCast(Message,Type1)

Select Type1

Case 1

For BP.Player = Each Player

WriteString (P\Stream,Message)

Next

Case 2

For BP.Player = Each Player

WriteInt(P\Stream,Message)

Next

End Select

End Function

-Client


Global On=False

Global Client

Global Message$

Global P.Player

Connect("LocalHost",7000)

P.Player = New Player


Graphics 800,600,32,2

ClsColor 100,100,100


SetBuffer FrontBuffer()

Global Player=LoadImage("Player.bmp")


Const UpKey=200

Const LeftKey=203

Const DownKey=208

Const RightKey=205


Type Player


Field ID%

Field Stream

Field Entity

Field Name$

Field x#

Field y#

Field z#

End Type


P\Stream=Client


P\Name$=Input$("Create A Name Here.")

WriteString(Client,P\Name$)

P\Id%=ReadInt(Client)

Print "Your PID Is " + P\Id%

Delay(1000)

p\x#=50

p\y#=90


While Not KeyHit(1)


CheckConnection

If ReadAvail(Client)

Message$=ReadString(Client)


End If


Cls

For P.Player=Each Player

If on=True Then
MessageTypeS

End If

DrawImage Player,p\x,p\y

If KeyDown(RightKey) P\x=P\x+5

If KeyDown(LeftKey) P\x=P\x-5

If KeyDown(DownKey) P\y=P\y+5

If KeyDown(UpKey) P\y=P\y-5

SendData


Flip

Next

On=True

Wend

;Functions

;Connect To Server Function ...........

Function Connect(IPAddress$,Port%)

Client=OpenTCPStream(IPAddress$,Port%)

If Client<>0

Print "Connection To Server Established ! "

Delay(1000)

Else

RuntimeError "Connection To Server UnSuccessfull "

End If

End Function

Function CheckConnection()

If Eof(Client)

RuntimeError "You have lost connection to the server"

End If


End Function

Function SendData ()

WriteString(Client,"Cordinates XYZD")

WriteString(Client,P\Name$)

WriteInt(Client,p\x#)

WriteInt(Client,p\y#)


End Function

Function MessageTypeS ()

Select Message$

Case "New Player"


P.Player = New Player

Case "Cordinates XYZD"

Name$=ReadString(Client)

If p\Name$ = Name$


Print "Player " + Name$

Else

p\x=ReadInt(Client)

p\y=ReadInt(Client)

End If

End Select

End Function



[This message has been edited by Xzider (edited April 03, 2005).]

[This message has been edited by Xzider (edited April 03, 2005).]

en972

Member

Posts: 562
From: NOT TELLING!
Registered: 08-27-2004
Um...what languagw is that?

------------------
Keep the holy day sacred.......halllllllukan

Rhyolite

Member

Posts: 86
From: UK
Registered: 08-04-2004
Its Blitz Basic. Any chance you could give us a clue about what does not work, what error message you are getting or something. Its a lot of code to trawl through not knowing what your looking for! Have you posted this on the Blitz forums?

And btw, have you looked at BlitzPlay? Its a networking library and comes in a free 'lite' version and a 'pro' version?

Rhy

Goldrush13

Member

Posts: 107
From:
Registered: 02-27-2005
First of all it'd be nice to hear the error message you get, Blitz error messages are very good for the programmer (if debug's on of course....)

Now that's a lot of code and I'm not really into online programming and my Blitz is a little rusty but I think anyone who knows Types could spot maybe a case change would be in order?

From:
For P.Player = Each Player
P\Name$=ReadString(p\Stream)
p\x#=ReadInt(p\Stream)
p\y#=ReadInt(p\Stream)

To:
For P.Player = Each Player
P\Name$=ReadString(p\Stream)
P\x#=ReadInt(P\Stream)
P\y#=ReadInt(P\Stream)

Then again I don't my Blitz but I only see one Type in that program and I'm pretty sure it belongs to the UPPER CASE P.

Just a thought.

I see you've left the topic for a couple of days, did you fix your problem?

I've copied this code to a doc and I'll look at it in more detail when I get the time, there could be something else wrong.

[This message has been edited by Goldrush13 (edited April 05, 2005).]

Xzider

Junior Member

Posts: 2
From: USA
Registered: 04-03-2005
No i didnt fix problem....

No error.

Just wont work, when i connect, it wont show player on all other clients..

sometimes it will lose connection too.

Goldrush13

Member

Posts: 107
From:
Registered: 02-27-2005
Ah, clients and servers and other network based things, not my forte I'm afraid, but in the immortal words of Tom Petty, "It'll all work out", of course he did write "Breakdown" as well, Tom Petty songs don't help do they?

What will help is blitzcoder.com, the forums there are really hot, no one is ever off them, people posting constantly, and as you can tell by the name, they specialise in Blitz, as soon as you post that code, people will take it and test it, and before you know it you've got ten replies on your hand, I go there for all my Blitz problems.....

Good luck.

Realm Master

Member

Posts: 1971
From: USA
Registered: 05-15-2005
hey xzider!

see your new here too.

Just found the place and its GREAT!

...hmm...sorry, i don't know any online server stuff yet.

------------------
God rules.

...no duh