also ich bin dabei nen kleines game zu proggen hab aba nen prob mit der übertagung der positionen der spieler.... und die spieler werden nciht gespawnt alles andere geht soweit.
server/client prinzip
bitte helft mir weiter...
server:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] Graphics 640,480,32,2 SetBuffer BackBuffer() AppTitle (\"Gameserver\")
Dim lines$(29)
Global stream,chat$ Global port=1334,makeid
Type pdata Field x Field y Field r Field name$ Field ip Field port,id End Type
Global rcon$ = \"rcontest\" Global cm_password$ = \"0\" Global mp_servername$= \"TEST SERVER NO 5\" Global mp_connectmessage$=\"n/a\" Global mp_playercount = 0 Global mp_maxplayers = 10
render() echo \"starte server...\" echo \"setze rcon = \"+rcon$ echo \"setze cm_password = \"+cm_password$
echo \"setze mp_servername = \"+mp_servername$ echo \"setze mp_connectmessage = \"+mp_connectmessage$ echo \"setze mp_maxplayers = \"+mp_maxplayers
stream=CreateUDPStream(port)
echo \"gestartet\" echo \"Local IP: localhost (127.0.0.1)\" echo \"IP: \"+ip() echo \"Port: \"+port
Repeat enter() render() update_server() Flip Forever
Function update_server() While RecvUDPMsg(stream) client_ip = UDPMsgIP(stream) client_port = UDPMsgPort(stream) If ReadAvail(stream) Then msgid=ReadByte(stream) Select msgid Case 0 WriteByte stream,0 WriteLine stream,cm_password$ WriteLine stream,mp_servername$ WriteLine stream,mp_connectmessage$ WriteLine stream,mp_playercount WriteLine stream,mp_maxplayers WriteLine stream,rcon$ SendUDPMsg stream,client_ip,client_port Case 1 msgtxt$=ReadLine(stream) p.pdata=New pdata p\name$=msgtxt$ p\ip=client_ip p\port=client_port p\id=makeid makeid=makeid+1 WriteByte stream,0 WriteByte stream,p\id SendUDPMsg stream,p\ip,p\port mp_playercount=mp_playercount+1 echo msgtxt$+\" ist dem Spiel beigetreten, ID: \"+p\id For p2.pdata = Each pdata WriteByte stream,1 WriteLine stream,msgtxt$ WriteByte stream,p2\id SendUDPMsg stream,p2\ip,p2\port Next Case 2 msgtxt$=ReadLine(stream) For p.pdata=Each pdata If p\name$=msgtxt$ WriteByte stream,2 WriteLine stream,msgtxt$ SendUDPMsg stream,p\ip,p\port
mp_playercount=mp_playercount-1 echo msgtxt$+\" hat das Spiel verlassen, ID: \"+p\id Delete p EndIf Next Case 3 msgtxt$=ReadLine(stream) chattxt$=ReadLine(stream) For p.pdata=Each pdata WriteByte stream,3 WriteLine stream,msgtxt$ WriteLine stream,chattxt$ SendUDPMsg stream,p\ip,p\port Next echo msgtxt$+\": \"+chattxt$ Case 4 For p.pdata=Each pdata p\x=ReadShort(stream) p\y=ReadShort(stream) WriteByte stream,4 WriteShort stream,p\x WriteShort stream,p\y SendUDPMsg stream,p\ip,p\port Next End Select EndIf Wend End Function
Function render() Cls Local i For i = 0 To 29 Text 3, 3+i*15, lines$(i) Next Text 3, 460, \"(>)\"+chat$ End Function
Function echo(msg$) Local i For i = 0 To 28 lines$(i)=lines$(i+1) Next lines$(29)=msg$ End Function Function enter() key=GetKey() If key>31 And key<>94 And key<>200 And key<>203 And key<>208 And key<>205 Then chat$=chat$+Chr(key) If KeyHit(14) And Len(chat$)>0 Then chat$=LSet(chat$, Len(chat$)-1) If KeyHit(28) And chat$<>\"\" Then If parse(chat$)=0 Then echo(myname$+\": \"+chat$) chat$=\"\" EndIf EndIf End Function Function parse(msg$) Select msg$ End Select End Function
Function ip$(inte=0) Local ips, ip, ipstr$ ips=CountHostIPs(\"\") If Not ips Then Return 0 ip=HostIP(ips) If inte=1 Then Return ip ipstr$=DottedIP(ip) Return ipstr$ End Function
---
client:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] Graphics 640,480,32,2 AppTitle(\"Client\")
Dim lines$(5) Dim linesc(5)
Global stream,x,y Global ip$ = \"127.0.0.1\" Global port=1334 Global myname$=\"LOL\"+Rand(1,415) Global chat$
Type pdata Field name$ Field x,y,id End Type
Global serverpassword$
Global rcon$ Global cm_password$ Global mp_servername$ Global mp_connectmessage$ Global mp_plyercount Global mp_maxplayers
Global avata Color 255,200,0 avata= CreateImage(10,10) SetBuffer ImageBuffer(avata) Oval 0,0,10,10,0 Plot 3,3 Plot 6,3 Plot 3,6 Plot 4,7 Plot 5,7 Plot 6,6 SetBuffer FrontBuffer() Color 255,255,255
stream=CreateUDPStream()
Print \"Stream erstellt\"
WriteByte stream,0 SendUDPMsg stream,int_ip(ip$),port Print \"connecting...\" Repeat If RecvUDPMsg(stream) Then If ReadAvail(stream) Then If ReadByte(stream)=0 Then cm_password$=ReadLine(stream) mp_servername$=ReadLine(stream) mp_connectmessage$=ReadLine(stream) mp_playercount=ReadLine(stream) mp_maxplayers=ReadLine(stream) rcon$=ReadLine(stream) Print \"connected!\" Print \"Server: \"+mp_servername$ Print \"message: \"+mp_connectmessage$ Print \"Spieler: \"+mp_playercount+\"/\"+mp_maxplayers If cm_password$<>\"\" Or cm_password$<>\" \" Then Print \"PW req.\" serverpassword$=Input(\"(>)\") If serverpassword$=cm_password$ Then Print \"PW OK\" WriteByte stream,1 WriteLine stream,myname$ SendUDPMsg stream,int_ip(ip$),port Exit Else Print \"Falsches Passwort, beende...\" WaitKey() End EndIf ElseIf cm_password$=\"\" Then Print \"NO PW\" Exit EndIf EndIf EndIf EndIf Forever Print \"Parsing Gameinfo\" Repeat If RecvUDPMsg(stream) Then If ReadAvail(stream) Then If ReadByte(stream)=0 Then p.pdata=New pdata myid=ReadByte(stream) p\id=myid x=200 y=200 Print \"Deine ID: \"+myid Exit EndIf EndIf EndIf Forever Print \"mainloop\" WaitKey timer=MilliSecs() Repeat If (MilliSecs()-timer)>10000 Then timer=MilliSecs() EndIf render() player() enter() update_client() If KeyHit(1) Then WriteByte stream,2 WriteLine stream,myname$ SendUDPMsg stream,int_ip(ip$),port End EndIf Flip Forever
Function msg(msg$, clr=0) Local i For i = 0 To 4 lines$(i)=lines$(i+1) linesc(i)=linesc(i+1) Next lines$(5)=msg$ linesc(5)=clr End Function
Function player() If KeyDown(2) Then x=x+1 For p.pdata=Each pdata DrawImage avata,p\x,p\y WriteByte stream,4 WriteShort stream,x WriteShort stream,y WriteByte stream,myid SendUDPMsg stream,int_ip(ip$),port Next End Function
Function render() Cls Local i For i = 0 To 5 Select linesc(i) Case 0 Color 255,255,255 Case 1 Color 255,0,0 Case 2 Color 0,255,0 End Select Text 3, 3+i*15, lines$(i) Next Color 255,200,0 Text 3, 93, \"(>)\"+chat$ Color 100,100,100 End Function Function parse(msg$) Select msg$ End Select End Function
Function enter() key=GetKey() If key>31 And key<>94 And key<>200 And key<>203 And key<>208 And key<>205 Then chat$=chat$+Chr(key) If KeyHit(14) And Len(chat$)>0 Then chat$=LSet(chat$, Len(chat$)-1) If KeyHit(28) And chat$<>\"\" Then If parse(chat$)=0 Then WriteByte stream,3 WriteLine stream,myname$ WriteLine stream,chat$ SendUDPMsg stream,int_ip(ip$),port chat$=\"\" EndIf EndIf End Function
Function update_client() While RecvUDPMsg(stream) If ReadAvail(stream) Then msgid=ReadByte(stream) Select msgid Case 0 Case 1 msgtxt$=ReadLine(stream) p.pdata=New pdata p\name$=msgtxt$ p\id=ReadByte(stream) msg (msgtxt$+\" connected\") Case 2 msgtxt$=ReadLine(stream) For p.pdata=Each pdata If p\name$=msgtxt$ Then Delete p Next msg (msgtxt$+\" Left\") Case 3 msgtxt$=ReadLine(stream) chattxt$=ReadLine(stream) msg(msgtxt$+\": \"+chattxt$) Case 4 For p.pdata = Each pdata p\x =ReadShort(stream) p\y=ReadShort(stream) Next End Select EndIf Wend End Function
Function INT_IP(IP$) a1=Int(Left(IP$,Instr(IP$,\".\")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,\".\")) a2=Int(Left(IP$,Instr(IP$,\".\")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,\".\")) a3=Int(Left(IP$,Instr(IP$,\".\")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,\".\")) a4=Int(IP$) Return (a1 Shl 24) + (a2 Shl 16) + (a3 Shl 8 ) +a4 End Function
|