Netzwerkchat

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

nX^

Betreff: Netzwerkchat

BeitragDo, Feb 24, 2005 20:29
Antworten mit Zitat
Benutzer-Profile anzeigen
Hier hab ich mal nen kleinen Chat für Lan (Direct Play):
Code: [AUSKLAPPEN]
Const W% = 640,H% = 480
Const MSGMAX% = 70
Global nettype% = 0,netdata$ = "",netfrom% = 0,netname$ = ""
Global msg$ = ""
Type chatter
   Field id%
   Field name$
End Type
Global my.chatter

;screen
AppTitle "Mini-Chat"
Graphics W,H,0,2
SetBuffer BackBuffer()

;start
Fade(0,255)
ausgabe = StartNetGame()
Fade(255,0)
If ausgabe <> 0 Then
   my.chatter = New chatter
   my\name = InputLetters("Your Name: ",3,8)
   my\id = CreateNetPlayer(my\name)
   Locate 0,20
Else
   RuntimeError "No Connection!"
EndIf

;### MAIN ###

Repeat

   ;input/send
   key = GetKey()
   If key >= 32 And key <= 126 And Len(msg) < MSGMAX Then msg = msg+Chr(key)
   If KeyHit(14) And Len(msg) > 0 Then msg = Left(msg,Len(msg)-1)
   If KeyHit(28) And msg <> "" Then SendNetMsg 1,msg,my\id,0,1 : Print my\name+": "+msg : msg = ""

   ;receive
   While RecvNetMsg() = 1
      nettype = NetMsgType()
      netdata = NetMsgData()
      netfrom = NetMsgFrom()
      netname = NetPlayerName(netfrom)
      If nettype = 1 Then
         Print netname+": "+netdata
      ElseIf nettype = 100 Then
         other.chatter = New chatter
         other\id = netfrom
         other\name = netname
         Print ">>> "+other\name+" has joined <<<"
      ElseIf nettype = 101 Or nettype = 102 Then
         For leaving.chatter = Each chatter
            If leaving\id = netfrom Then
               Print ">>> "+leaving\name+" has left <<<"
               Delete leaving.chatter
            EndIf
         Next
      EndIf
   Wend

   ;output
   Color 70,70,70
    Rect 0,0,640,18
   Color 255,255,255
    Line 0,18,W,18
    Text 2,2,"SEND: "+msg

Flip
Until KeyHit(1)
Fade(0,255)
End

;### FUNC ###

Function InputLetters$(infotxt$,min%,max%)
   Local key%,txt$
   Repeat
   Cls
      key = GetKey()
      If (Len(txt) < max) And ((key >= 65 And key <= 90) Or (key >= 97 And key <= 122)) Then txt = txt+Chr(key)
      If KeyHit(14) And Len(txt) > 0 Then txt = Left(txt,Len(txt)-1)
      If KeyHit(28) Then
         If Len(txt) >= min Then
            Exit
         Else
            Text 0,0,"Number of letters must be >= "+min+" and <= "+max : Flip
            FlushKeys() : WaitKey() : FlushKeys()
         EndIf
      EndIf
      Text 0,0,infotxt+""+txt
   Flip
   Forever
   Return txt
End Function
Function Fade(von%,nach%)
   If von < nach Then
      For i = von To nach Step 5
         ClsColor i,i,i : Cls : Flip
      Next
   ElseIf von > nach Then
      For i = von To nach Step -5
         ClsColor i,i,i : Cls : Flip
      Next
   EndIf
End Function
 

noir

BeitragDo, Feb 24, 2005 20:37
Antworten mit Zitat
Benutzer-Profile anzeigen
... wenns nicht mit directplay wäre, könnte man es vielleicht brauchen, aber so...

nix für ungut, aber nicht unbedingt was für das codearchiv..
Fragt und man wird euch helfen

Das Alternativ BlitzBasic-Forum: FreeCoder
Einfach chatten: BlitzChat
Code&Text schnell und einfach pasten: FreePasting
  • Zuletzt bearbeitet von noir am So, März 06, 2005 12:22, insgesamt einmal bearbeitet

nX^

BeitragDo, Feb 24, 2005 20:54
Antworten mit Zitat
Benutzer-Profile anzeigen
ok

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group