How to use raknet module?

Started by William, March 04, 2024, 17:36:04

Previous topic - Next topic

William

i'm referencing its docs and example files.

but the examples included in bruceys raknet module do not work. i am trying to program it myself based on sources like docs and the included example bmx files.

but it cannot find trkraknetpeer or raknetpeerinterface, i am unable to access its type methods and type classes.

Code: BASIC
'

SuperStrict

Framework BaH.Raknet
Import BRL.StandardIO
'Import "example_helper.bmx"

AppTitle = "ChatServer"



Type GameServer

	Const STAGE_NONE:Int = 0
	Const STAGE_GET_SERVER_PORT:Int = 1
	Const STAGE_SET_BAN:Int = 2
	Const STAGE_GET_MESSAGE:Int = 3

	Field stage:Int = STAGE_NONE

	Field rss:TRKRakNetStatistics
	Field server:TRKRakPeer = TRKRakPeer.GetRakPeerInterface()
	
	Field clientID:TRKSystemAddress = UNASSIGNED_SYSTEM_ADDRESS

	Field p:TRKPacket
	Field packetIdentifier:Int
	
	'Field clientPort:Int
	Field serverPort:Int = 43594
	Field ip:String

	Method Init()

	End Method
	
	Method RenderExtra()
	End Method

	Method Update()

		' Get a packet from either the server or the client
		
		p = server.Receive()
		
		
		If Not p Then
			Return ' Didn't get any packets
		End If
		
		' We got a packet, get the identifier with our handy function
		packetIdentifier = p.GetPacketIdentifier()
		
		' Check if this is a network message packet
		Select packetIdentifier
		
			Case ID_DISCONNECTION_NOTIFICATION
				  ' Connection lost normally
				AddMessage "ID_DISCONNECTION_NOTIFICATION"

			Case ID_NEW_INCOMING_CONNECTION
				' Somebody connected.  We have their IP now
				clientID = p.GetSystemAddress()

			Case ID_MODIFIED_PACKET
				' Cheater!
				Print "Cheater: ID_MODIFIED_PACKET"
		
			Case ID_CONNECTION_LOST
				' Couldn't deliver a reliable packet - i.e. the other system was abnormally
				' terminated
				Print "ID_CONNECTION_LOST"
		
			Default

				' The server knows the static data of all clients, so we can prefix the message
				' With the name data
				Local value:String = String.FromUTF8String(p.GetData())
				AddMessage value

				' Relay the message.  We prefix the name For other clients.  This demonstrates
				' That messages can be changed on the server before being broadcast
				' Sending is the same as before
				Local message:Byte Ptr = value.ToUTF8String()
				server.Send(message, String.FromCString(message).Length + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, p.GetSystemAddress(), True)
				MemFree(message)


		End Select
		
		
		' We're done with the packet
		server.DeallocatePacket(p)
		
	End Method
	
	Method OnSubmit(value:String)
		Select stage
			Case STAGE_GET_SERVER_PORT
				
				serverPort = value.ToInt()
				
				If Not serverPort Then
					serverPort = 10000
				End If
				
				Print "Starting server."

				' Starting the server is very simple.  2 players allowed.
				' 0 means we don't care about a connectionValidationInteger, and false
				' for low priority threads
				Local socketDescriptor:TRKSocketDescriptor = New TRKSocketDescriptor.Create(serverPort)
				Local b:Int = server.Startup(32, 30, socketDescriptor)
				server.SetMaximumIncomingConnections(2)
				
				If b Then
					Print "Server started, waiting for connections."
				Else
					Print "Server failed to start.  Terminating."
					quit = True
				End If
				
				server.SetOccasionalPing(True)
			
				Print "My IP is " + server.GetLocalIP(0)
				Print "My GUID is " + server.GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS).ToString()
				Print "'quit' to quit. 'stat' to show stats. 'ping' to ping."
				Print "'ban' to ban an IP from connecting. 'kick to kick the first connected player. Type to talk."
				
				ShowChatWindow()
			
			Case STAGE_SET_BAN
			
				If value Then
					server.AddToBanList(value)
					Print "IP " + value + " added to ban list."
				End If

				

			Case STAGE_GET_MESSAGE
			
				Select value
					Case "quit"
						AddMessage "Quitting."
						quit = True
					
						Return
					Case "stat"
					
						rss = server.GetStatistics(server.GetSystemAddressFromIndex(0))
						Local s:String = rss.ToVerboseString(2)
						s = s.Replace("~t", "    ")
						
						Local lines:String[] = s.Split("~n")
						For Local i:Int = 0 Until lines.Length
							Print lines[i]
						Next
						
						Print "Ping " + server.GetAveragePing(server.GetSystemAddressFromIndex(0))
					
						

						Return
					Case "ban"
					
						stage = STAGE_SET_BAN
						RequestValue("Ban IP", "Enter IP To ban.  You can use * as a wildcard")
						

						Return
					Case "kick"
					
						server.CloseConnection(clientID, True, 0)

						

						Return
					Case "ping"
					
						server.Ping(clientID)

						

						Return
				End Select
				
				
				value = "Server: " + value
				' message is the data To send
				' strlen(message)+1 is To send the Null terminator
				' HIGH_PRIORITY doesn't actually matter here because we don't use any other priority
				' RELIABLE_ORDERED means make sure the message arrives in the right order
				Local message:Byte Ptr = value.ToCString()
				server.Send(message, value.Length + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, True)
				MemFree(message)
		
				ShowChatWindow()

		End Select
		
	End Method
	

	
	Method Finalize()
	
		server.Shutdown(300)
		' We're done with the network
		TRKRakNetworkFactory.DestroyRakPeerInterface(server)
		
	End Method

End Type
I'm just a mentally ill person stuck in person. I've had quite an online history and of media such as role plays with people that became movies (for real) among other things and content. I wanted to be an online famous person at one time. Unfortunately it's ill and I'm anonymous.

Derron

I am not sure what the state of the raknet-module is ..


This "?temp" is a conditional. If "temp" evaluates to "True", the following code is "used", if it evaluates to "False", it is skipped.
Any "?bla"-block ends with a "?"  (which is in the last line of that source file).

Any "unknown" variable (for Bmx-NG) in the conditionals is "False".

Means: the code inside the module is effectively not "used" (not "existing"). Which explains why you cannot find the type.


bye
Ron

William

okay can you help me get it compiled? i dont understand why this code previously worked and now it doesnt (but who knows the present C code is compatible with the latest gcc compiler)


Code: BASIC
	Method RPC:Int(id:String, data:Byte Ptr, bitLength:Int, priority:Int, reliability:Int, orderingChannel:Int, addr:TRKSystemAddress, ..
			broadcast:Int, includedTimestamp:Long Var, replyFromTarget:TRKBitStream = Null)
		
		If data Then
			If addr Then
				If replyFromTarget Then
					Return bmx_RakPeer_RPC(rakPeerPtr, id, data, bitLength, priority, reliability, orderingChannel, addr.systemAddressPtr, broadcast, Varptr includedTimestamp, replyFromTarget.bitStreamPtr)

it says
Quote[  7%] Processing:raknet.bmx
Compile Error: Unable to convert from Void to Int.
[/home/william/Documents/BlitzMax/mod/bah.mod/raknet.mod/raknet.bmx;717;0]
Build Error: failed to compile (65280) /home/william/Documents/BlitzMax/mod/bah.mod/raknet.mod/raknet.bmx
I'm just a mentally ill person stuck in person. I've had quite an online history and of media such as role plays with people that became movies (for real) among other things and content. I wanted to be an online famous person at one time. Unfortunately it's ill and I'm anonymous.

Derron

I do not have the time (and for now also not the will, maybe even not the skill) to help you to get the raknet module to compile with NG. I can just chime in here and there ... to explain "basic stuff" so you can try on your own.


It is made for "vanilla" and was not ported to NG.
The raknet library itself is marked as "read only", so facebook (who bought oculus, the owner) most probably won't develop it further - you might need to find a viable fork then.


> Compile Error: Unable to convert from Void to Int.

As the error states - you have a function not returning anything ("void") but expecting it to return an "int".

bmx_RakPeer_RPC is defined ("for blitzmax") in common.bmx
Code: Blitzmax
	Function bmx_RakPeer_RPC(handle:Byte Ptr, id:Byte Ptr, data:Byte Ptr, bitLength:Int, priority:Int, reliability:Int, ..
		orderingChannel:Int, addr:Byte Ptr, broadcast:Int, includedTimestamp:Long Ptr, ..
		replyFromTarget:Byte Ptr)

As you see it does not return anything. In "NG" things are "strict", so you define "nothing" and get "nothing". In vanilla "nothing" was always assuming "int".


the function itself is defined "for C++" in glue.cpp:
Code: C
bool bmx_RakPeer_RPC(RakPeerInterface * peer, const char * id, const char * data, unsigned int bitLength, 
		PacketPriority priority, PacketReliability reliability, int 		orderingChannel,
		MaxSystemAddress * addr, bool broadcast, BBInt64 * includedTimestamp, 
		RakNet::BitStream * replyFromTarget) {

	bool ret;

There you see it returns "bool" (true, false) - which is something we normally interpret as "int" in Blitzmax. So your "extern definition" in the common.bmx must be changed to return ":int" instead of nothing.


bye
Ron