Hello, me again. Over the past few weeks I have been working on a new kind of multiplayer plugin, one for peer-to-peer games rather than client/server and also designed in the way of speed rather than reliability. One of the main reasons for this, is because I have been doing some tests and I have realised I can get data transfering between players considerably quicker between players using a different method to that of current plugins(with the cost of reliability).
I want this to be capable of use in FPS-type games where optimal data transfer speed is needed rather than total reliability. However, I realise that for some tasks in such games reliability is also needed, therefore I am making a reliable message transfering system. What I have done so far is the system to get all players connected with eachother, and a basic message system. The message system can store 60 messages at one time(I will change this, but for now it is enough) and it can use message IDs.
Because of how this plugin works, I will have to program a lot more than before(with my other project, Multisync) but because of that it means I have a lot more power over what happens, and therefore I can design the whole thing around multiplayer game data transfering. Systems such as the ping system, will be based around the fact that pinging will only have to be done when there is a lack of activity(due to players not transfering data between eachother). I have a feeling I can make this quite powerfull(yet easy to use) and fast, and so far its looking quite good.
What I need at this stage is people to test this for me, to see how well it works for them, and if it does work for them. I have attached the dll to this post and the code is below, so testing should be fairly easy. The code is a basic peer-to-peer chat program. You'll probably find that only 4 players can be connected at one time, and a 5th player will just crash it. I'm not sure exactly what this bug is, but I don't think its extrememly serious and I think I'll be able to fix it in a while. Also note that if you are behind a router, this may work a bit odd because of the way it retrieves your IP. If you are infact connected in some sort of LAN then to get other computers to connect then they just have to specify your LAN ip.
To use the chat program, first choose someone to host. This can be anyone, but theres a big possibility that they will have to temporarily turn off their firewall(unless they enable access through ports 3999 and 3998). When joining the chat, you enter the ip address of the person who is hosting and you should(hopefully) be able to connect. You may notice that for a while player names will be just ???? which is fine because it just means you haven't received the player name from that player yet. If the real username doesn't ever appear, it is either because they can't transfer data to you or because they have disconnected. Neither the chat program nor the DLL itself can yet detect when a player has disconnected, so remember that when you are yelling at someone waiting for them to respond.
Be sure to give your comments/questions/problems after trying it. Remember its important that I know any problems that arise so I know to fix them.
Thanks.
` globals & constants ----------
#constant NET_SYNC call dll 1,"Sync"
global dim MSGQUEUE$(30) as string
global MSGCOUNT
global TEXT_ENTERED$ as string
global RETURNKEY_DOWN as boolean
global USERNAME$ as string
`-------------------------------
`load the dll
load dll "tempest.dll",1
print "1. Host"
print "2. Join"
print
input "",choice
print
input "Username: ",USERNAME$
if choice=1
connected = call dll(1,"Host","&",10,USERNAME$)
endif
if choice=2
input "IP: ",ip$
input "Port(leave blank if you don't know): ",port$
if port$="" then port$="3998"
port = val(port$)
call dll 1,"SetLocalPort",port
connected = call dll(1,"Join",ip$,USERNAME$)
endif
if connected=0 then end
set window title "p2p chat | IP: "+ip$+" | Username: "+USERNAME$
sync on
sync rate 0
clear entry buffer
repeat
until returnkey()=0
do
cls rgb(127,127,127)
DisplayPlayers(screen width()-155,5)
DisplayMessages()
DrawInputBox()
HandleEntry()
MessageHandle()
NET_SYNC
sync
loop
function HandleEntry()
new$=ENTRY$()
for a=1 TO LEN(new$)
if ASC(MID$(new$,a))=8
TEXT_ENTERED$=left$(TEXT_ENTERED$,len(TEXT_ENTERED$)-1)
else
TEXT_ENTERED$ = TEXT_ENTERED$+mid$(new$,a)
endif
next a
clear entry buffer
`If returnkey, send message
if returnkey() and RETURNKEY_DOWN=0
SendString(TEXT_ENTERED$)
AddMsgToQueue(USERNAME$+": "+TEXT_ENTERED$)
TEXT_ENTERED$ = "";
RETURNKEY_DOWN = 1
endif
`If returnkey is up, reset variable
if returnkey()=0 then RETURNKEY_DOWN=0
endfunction
function MessageHandle()
newmsg = call dll(1,"GetMsg")
if newmsg
pfrom = call dll(1,"PlayerFrom")
name$ = call dll(1,"GetPlayerName",pfrom)
temp$ = ""
length = call dll(1,"PopChar")
for x=1 to length
char = call dll(1,"PopChar")
temp$ = temp$ + chr$(char)
next x
AddMsgToQueue(name$+": "+temp$)
endif
`clear message queue to prevent overflow
repeat
newmsg = call dll(1,"GetMsg")
until newmsg=0
endfunction
function AddMsgToQueue(myStr$)
if MSGCOUNT>29 then ShiftQueue() : MSGCOUNT=29
MSGQUEUE$(MSGCOUNT) = myStr$
inc MSGCOUNT
endfunction
function ShiftQueue()
for x=1 to 30
MSGQUEUE$(x-1) = MSGQUEUE$(x)
next x
endfunction
function SendString(myStr$)
for x=len(mystr$) to 1 step -1
call dll 1,"PushChar",asc(mid$(myStr$,x))
next x
call dll 1,"PushChar",len(myStr$)
call dll 1,"SendAll"
endfunction
` Graphical functions -----------------------
`--------------------------------------------
`--------------------------------------------
function DisplayMessages()
for x=0 to MSGCOUNT
if x<30 then text 5,14*x+5,MSGQUEUE$(x)
next x
endfunction
function DisplayPlayers(xOffset,yOffset)
ink rgb(240,240,240),0
box xOffset,yOffset,xOffset+150,yOffset+200
ink rgb(200,200,200),0
box xOffset+2,yOffset+2,xOffset+148,yOffset+198
ink rgb(0,0,0),0
box xOffset+5,yOffset+4,xOffset+145,yOffset+19
ink rgb(255,0,0),0
center text xOffset+82,yOffset+4,"Player list"
ink rgb(255,255,255),0
for x=0 to 4
name$ = call dll(1,"GetPlayerName",x)
text xOffset+10,14*x+yOffset+20,str$(x)
center text xOffset+75,14*x+yOffset+20,name$
next x
endfunction
function DrawInputBox()
ink rgb(200,200,200),0
box 10,screen height()-40,screen width()-10,screen height()-10
ink rgb(0,255,0),0
box 15,screen height()-34,screen width()-15,screen height()-17
ink 0,0
center text 30,screen height()-33,"-> "
text 45,screen height()-33,TEXT_ENTERED$
endfunction
"Lets migrate like bricks" - Me