OK, hab mich mal bei DynDNS angemeldet, kann meinen Server zwar noch nicht erreichen, aber das wird schon denk ich.
Ich hab mal ein erstes Online Spiel geschriebn, Pingpong für 2 Spieler Online - aber es funzt natürlich nicht. Ich hab so keine Ahnung was falsch ist

Habe schon fast alles versucht, sogar mit nem einfachen Bot der mir Random was rüberschiebt (was funktioniert hat^^)
Hier mal der Code für den Host:
Code: Alles auswählen
Port = 6832
InitNetwork()
OpenWindow(0,100,100,500,500,"PP :D")
StickyWindow(0,1)
EditorGadget(0,1,1,498,470)
modus = MessageRequester("Modus wählen...","Möchten sie im Vollbildmodus spielen???",#PB_MessageRequester_YesNo)-5
speed=Val(InputRequester("Speed","Bitte Startwert für Speed eingeben.","4"))
Procedure.s username()
s1$=GetHomeDirectory()
i=Len(s1$)-1
While Mid(s1$,i,1)<>"\"
i=i-1
Wend
s1$=Mid(s1$,i+1,Len(s1$)-i-1)
ProcedureReturn s1$
EndProcedure
Procedure AddL(Text$)
AddGadgetItem(0,CountGadgetItems(0)+1,Text$)
EndProcedure
Procedure Sende(CID,Text$)
Delay(20)
SendNetworkString(CID,Text$)
EndProcedure
Procedure SendeInt(CID,Zahl)
Delay(20)
*Buffer=AllocateMemory(10)
PokeI(*Buffer,Zahl)
SendNetworkData(CID,*Buffer,10)
EndProcedure
addl("Erstelle Server...")
user$=username()
If CreateNetworkServer(0,port)
addl("Server erstellt.")
addl("Speed="+Str(speed))
addl("Warte auf Mitspieler.")
Repeat
WindowEvent=WaitWindowEvent(10)
If WindowEvent= #PB_Event_CloseWindow
End
EndIf
SEvent=NetworkServerEvent()
If sevent
CID = EventClient()
Select SEvent
Case 1
Addl("Neuer Client verbunden: CID="+Str(CID)+", IP="+IPString(GetClientIP(CID)))
Case 2
*Buffer = AllocateMemory(1000)
ReceiveNetworkData(CID, *Buffer, 1000)
s1$=PeekS(*Buffer)
addl("Nachricht: "+s1$)
If s1$ = "Hier ist ein Pingpong-Client, let's play a game!"
quit=1
t1=ElapsedMilliseconds()
addl("Pingpong-Client verbunden, starte in 5s!")
Sende(CID,"User: "+user$)
sende(CID,"Speed: "+Str(speed))
Sende(CID,"OK, verstanden, aufi!")
addl("Bestätigung gesendet.")
EndIf
If CountString(s1$,"User: ")
user2$=RemoveString(s1$,"User: ")
addl("Spieler2="+user2$)
EndIf
Case 4
addl("Client "+Str(CID)+" hat die verbindung geschlossen.")
quit=0
EndSelect
EndIf
Until (quit=1 And ElapsedMilliseconds()-t1>5000)
EndIf
InitSprite()
InitKeyboard()
If modus=1
OpenScreen(1024,768,32,"Online PingPong")
Else
OpenWindow(1,10,10,1024,768,"PingPong by David Fritsche :P",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,1024,768,0,0,0)
EndIf
UsePNGImageDecoder()
CatchSprite(0,?Back)
CatchSprite(1,?Paddle)
CatchSprite(2,?Ball)
CreateSprite(3,100,30)
CreateSprite(4,100,30)
LoadFont(0,"Arial",24)
StartDrawing(SpriteOutput(3))
DrawingFont(FontID(0))
DrawText(0,0,"0",RGB(255,50,50),RGB(0,0,0))
StopDrawing()
StartDrawing(SpriteOutput(4))
DrawingFont(FontID(0))
DrawText(0,0,"0",RGB(255,50,50),RGB(0,0,0))
StopDrawing()
x_richtung=1
y_richtung=2
b_x=55
Repeat
Delay(20)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
p1_y=p1_y+10
If p1_y>768-100
p1_y=768-100
EndIf
EndIf
If KeyboardPushed(#PB_Key_Up)
p1_y=p1_y-10
If p1_y<0
p1_y=0
EndIf
EndIf
If KeyboardPushed(#PB_Key_Escape)
sende(CID,"Abbruch")
Delay(20)
CloseNetworkServer(0)
CloseScreen()
End
EndIf
SEvent=NetworkServerEvent()
If sevent=2
*Buffer=AllocateMemory(1000)
ReceiveNetworkData(cid,*Buffer,1000)
p2_y=Val(PeekS(*Buffer))
Debug "p2_y_received:"+Str(p2_y)
Sende(CID,"P:"+Str(p1_y))
sende(CID,"BX:"+Str(b_x))
sende(CID,"BY:"+Str(b_y))
EndIf
If sevent=4
CloseScreen()
MessageRequester("!","Client disconnectet.")
End
EndIf
Gosub moveball
Gosub checkcrash
Gosub drawall
ForEver
drawall:
DisplaySprite(0,0,0)
DisplayTransparentSprite(3,10,768-40)
DisplayTransparentSprite(4,1024-100,768-40)
DisplayTransparentSprite(1,5,p1_y)
DisplayTransparentSprite(1,1024-55,p2_y)
DisplayTransparentSprite(2,b_x,b_y)
FlipBuffers()
Return
moveball:
b_x=B_x+x_richtung*speed
b_y=b_y+y_richtung*speed
crash=0
If b_x>=1024-100
b_x=1024-100
x_richtung=x_richtung*-1
speed=speed+1
crash=2
EndIf
If b_X<=0
b_x=0
x_richtung=x_richtung*-1
speed=speed+1
crash=1
EndIf
If b_y>=768-100
b_y=768-100
y_richtung=y_richtung*-1
EndIf
If b_y<=0
b_y=0
y_richtung=y_richtung*-1
EndIf
Return
checkcrash:
If b_x>=1024-155 Or b_x<=55
If (SpritePixelCollision(1,5,p1_y,2,b_x,b_y) And x_richtung=-1 And crash=0) Or (SpritePixelCollision(1,1024-55,p2_y,2,b_x,b_y) And x_richtung=1 And crash=0)
x_richtung=x_richtung*-1
EndIf
If crash=1
Punkte_Client=Punkte_client+1
EndIf
If crash=2
Punkte_Host=Punkte_Host+1
EndIf
StartDrawing(SpriteOutput(3))
Box(0,0,100,30,RGB(0,0,0))
DrawingFont(FontID(0))
DrawText(0,0,Str(Punkte_Host),RGB(255,50,50),RGB(0,0,0))
StopDrawing()
StartDrawing(SpriteOutput(4))
Box(0,0,100,30,RGB(0,0,0))
DrawingFont(FontID(0))
DrawText(0,0,Str(Punkte_Client),RGB(255,50,50),RGB(0,0,0))
StopDrawing()
EndIf
Return
End
Back: IncludeBinary "Back.png"
Paddle: IncludeBinary "Paddle.png"
Ball: IncludeBinary "Ball.png"
Und hier für den Client:
Code: Alles auswählen
modus = MessageRequester("Modus wählen...","Möchten sie im Vollbildmodus spielen???",#PB_MessageRequester_YesNo)-5
InitNetwork()
OpenWindow(0,200,200,500,500,"PP :D")
StickyWindow(0,1)
EditorGadget(0,1,1,498,470)
Procedure.s username()
s1$=GetHomeDirectory()
i=Len(s1$)-1
While Mid(s1$,i,1)<>"\"
i=i-1
Wend
s1$=Mid(s1$,i+1,Len(s1$)-i-1)
ProcedureReturn s1$
EndProcedure
Procedure AddL(Text$)
AddGadgetItem(0,CountGadgetItems(0)+1,Text$)
EndProcedure
Procedure Senden(CID,Text$)
Delay(20)
SendNetworkString(CID,Text$)
EndProcedure
Procedure SendeInt(CID,Zahl)
Delay(20)
*Buffer=AllocateMemory(1000)
PokeI(*Buffer,Zahl)
SendNetworkData(CID,*Buffer,1000)
EndProcedure
ip$=InputRequester("Bitte IP eingeben!","IP des Hosts eingeben...","78.43.161.22")
user$=username()
addl("Verbinde...")
Delay(100)
WindowEvent()
cid=OpenNetworkConnection(ip$,6832)
If cid
Senden(cid,"Hier ist ein Pingpong-Client, let's play a game!")
senden(cid,"User: "+user$)
Repeat
WEvent=WaitWindowEvent(20)
Delay(10)
If WEvent=#PB_Event_CloseWindow
CloseNetworkConnection(CID)
End
EndIf
NEvent=NetworkClientEvent(CID)
If nevent=2
*buffer=AllocateMemory(1000)
ReceiveNetworkData(CID,*buffer,1000)
s1$ = PeekS(*buffer)
If CountString(s1$,"User: ")
user2$=RemoveString(s1$,"User: ")
addl("Spieler1="+user2$)
EndIf
If CountString(s1$,"Speed: ")
speed=Val(RemoveString(s1$,"Speed: "))
addl("Speed="+Str(speed))
EndIf
If s1$="OK, verstanden, aufi!"
addl("Server bestätigt, starte in 5s")
quit=1
t1=ElapsedMilliseconds()
EndIf
EndIf
Until quit=1 And ElapsedMilliseconds()-t1>5000
;CreateFile(0,GetHomeDirectory()+"Log.txt")
InitSprite()
InitKeyboard()
If modus=1
OpenScreen(1024,768,32,"Online PingPong")
Else
OpenWindow(1,10,10,1024,768,"PingPong by David Fritsche :P",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,1024,768,0,0,0)
EndIf
UsePNGImageDecoder()
CatchSprite(0,?Back)
CatchSprite(1,?Paddle)
CatchSprite(2,?Ball)
CreateSprite(3,100,30)
CreateSprite(4,100,30)
LoadFont(0,"Arial",24)
StartDrawing(SpriteOutput(3))
DrawingFont(FontID(0))
DrawText(0,0,"0",RGB(255,50,50),RGB(0,0,0))
StopDrawing()
StartDrawing(SpriteOutput(4))
DrawingFont(FontID(0))
DrawText(0,0,"0",RGB(255,50,50),RGB(0,0,0))
StopDrawing()
x_richtung=-1
y_richtung=2
b_x=1024-55
Repeat
Delay(10)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
p1_y=p1_y+10
If p1_y>768-100
p1_y=768-100
EndIf
EndIf
If KeyboardPushed(#PB_Key_Up)
p1_y=p1_y-10
If p1_y<0
p1_y=0
EndIf
EndIf
If KeyboardPushed(#PB_Key_Escape)
Delay(10)
CloseFile(0)
CloseNetworkConnection(CID)
Delay(10)
CloseScreen()
End
EndIf
Senden(CID,Str(p1_y))
NEvent=NetworkClientEvent(CID)
;WriteStringN(0,"ClientEvent: "+Str(NEvent))
If NEvent=2
*Buffer=AllocateMemory(1000)
ReceiveNetworkData(cid,*Buffer,1000)
s1$=PeekS(*Buffer)
If CountString(s1$,"P:")
p2_y=Val(RemoveString(s1$,"P:"))
EndIf
If CountString(s1$,"BX:")
b_x=1024-Val(RemoveString(s1$,"BX:"))
EndIf
If CountString(s1$,"BY:")
b_y=Val(RemoveString(s1$,"BY:"))
EndIf
If s1$="Abbruch"
CloseScreen()
MessageRequester("Abbruch:","Der Server wurde geschlossen.")
End
EndIf
addl("Daten empfangen:"+s1$)
;WriteStringN(0,"s1$: "+s1$)
EndIf
Gosub moveball
Gosub checkcrash
Gosub drawall
ForEver
drawall:
DisplaySprite(0,0,0)
DisplayTransparentSprite(3,10,768-40)
DisplayTransparentSprite(4,1024-100,768-40)
DisplayTransparentSprite(1,5,p1_y)
DisplayTransparentSprite(1,1024-55,p2_y)
DisplayTransparentSprite(2,b_x,b_y)
FlipBuffers()
Return
moveball:
b_x=B_x+x_richtung*speed
b_y=b_y+y_richtung*speed
crash=0
If b_x>=1024-100
b_x=1024-100
x_richtung=x_richtung*-1
speed=speed+1
crash=2
EndIf
If b_X<=0
b_x=0
x_richtung=x_richtung*-1
speed=speed+1
crash=1
EndIf
If b_y>=768-100
b_y=768-100
y_richtung=y_richtung*-1
EndIf
If b_y<=0
b_y=0
y_richtung=y_richtung*-1
EndIf
Return
checkcrash:
If b_x>=1024-155 Or b_x<=55
If (SpritePixelCollision(1,5,p1_y,2,b_x,b_y) And x_richtung=-1 And crash=0) Or (SpritePixelCollision(1,1024-55,p2_y,2,b_x,b_y) And x_richtung=1 And crash=0)
x_richtung=x_richtung*-1
EndIf
If crash=1
Punkte_Client=Punkte_client+1
EndIf
If crash=2
Punkte_Host=Punkte_Host+1
EndIf
StartDrawing(SpriteOutput(3))
Box(0,0,100,30,RGB(0,0,0))
DrawingFont(FontID(0))
DrawText(0,0,Str(Punkte_Host),RGB(255,50,50),RGB(0,0,0))
StopDrawing()
StartDrawing(SpriteOutput(4))
Box(0,0,100,30,RGB(0,0,0))
DrawingFont(FontID(0))
DrawText(0,0,Str(Punkte_Client),RGB(255,50,50),RGB(0,0,0))
StopDrawing()
EndIf
Return
EndIf
End
Back: IncludeBinary "Back.png"
Paddle: IncludeBinary "Paddle.png"
Ball: IncludeBinary "Ball.png"
Und die Bilder wer will...
http://img251.imageshack.us/g/backlr.png/
Ich hoffe ihr könnt mir helfen!!! Habs echt 10000x mit Freunden probiert
