1. Post #1
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Description:

    This is a revamp of sourcenet, a module designed to expose Source's networking.

    Notes:

    - All allocated objects (sn3_bf_write, sn3_bf_read, UCHARPTR, dataFragments_t) must be freed, see examples.
    - Do not call :FinishReading/Writing on bit buffers passed as arguments, only free objects you create.
    - If you're not using the hooking base, always detach from functions before you change level. Not doing so will cause a crash.

    SVN:

    http://christopherthorne.googlecode....gm_sourcenet3/

    Includes Windows and Linux binaries, as well as the source code and examples.

    Global Functions:

    Code:
    -- Client: Retrieves server net channel
    -- Server: Retrieves specified player's net channel
    CNetChan( [number] entindex ) [CNetChan]
    
    -- Creates a new write bitbuf
    -- Always call FinishWriting after you've finished writing
    sn3_bf_write( [UCHARPTR] data, [number] bits ) [sn3_bf_write]
    
    -- Creates a new read bitbuf
    -- Always call FinishReading after you've finished reading
    sn3_bf_read( [UCHARPTR] data, [number] bits ) [sn3_bf_read]
    
    -- Allocates new fragments class
    -- Always call Delete when you've finished with the object
    dataFragments_t() [dataFragments_t]
    
    -- Allocates specified bytes
    -- Always call Delete when you've finished with the memory
    UCHARPTR( [number] bytes ) [UCHARPTR]
    
    -- Returns network string table container
    INetworkStringTableContainer() [INetworkStringTableContainer]
    
    -- Returns game event manager
    IGameEventManager2() [IGameEventManager2]
    
    -- Hooking functions (Always detach before unloading the module)
    
    -- PreProcessPacket( [CNetChan] netchan )
    -- PostProcessPacket( [CNetChan] netchan )
    Attach__CNetChan_ProcessPacket( [CNetChan] netchan )
    Detach__CNetChan_ProcessPacket( [CNetChan] netchan )
    
    -- PreSendDatagram( [CNetChan] netchan, [sn3_bf_write] extradata, [sn3_bf_write] reliabledata, [sn3_bf_write] unreliabledata, [sn3_bf_write] voicedata )
    -- PostSendDatagram( [CNetChan] netchan )
    Attach__CNetChan_SendDatagram( [CNetChan] netchan )
    Detach__CNetChan_SendDatagram( [CNetChan] netchan )
    
    -- PreNetChannelShutdown( [CNetChan] netchan, [string] reason )
    -- PostNetChannelShutdown()
    Attach__CNetChan_Shutdown( [CNetChan] netchan )
    Detach__CNetChan_Shutdown( [CNetChan] netchan )
    
    -- INetChannelHandler::ConnectionStart( [INetChannelHandler] handler, [CNetChan] netchan )
    Attach__INetChannelHandler_ConnectionStart( [INetChannelHandler] handler )
    Detach__INetChannelHandler_ConnectionStart( [INetChannelHandler] handler )
    
    -- INetChannelHandler::ConnectionClosing( [INetChannelHandler] handler, [string] reason )
    Attach__INetChannelHandler_ConnectionClosing( [INetChannelHandler] handler )
    Detach__INetChannelHandler_ConnectionClosing( [INetChannelHandler] handler )
    
    -- INetChannelHandler::ConnectionCrashed( [INetChannelHandler] handler, [string] reason )
    Attach__INetChannelHandler_ConnectionCrashed( [INetChannelHandler] handler )
    Attach__INetChannelHandler_ConnectionCrashed( [INetChannelHandler] handler )
    
    -- INetChannelHandler::PacketStart( [INetChannelHandler] handler, [number] incoming_sequence, [number] outgoing_sequence )
    Attach__INetChannelHandler_PacketStart( [INetChannelHandler] handler )
    Detach__INetChannelHandler_PacketStart( [INetChannelHandler] handler )
    
    -- INetChannelHandler::PacketEnd( [INetChannelHandler] handler )
    Attach__INetChannelHandler_PacketEnd( [INetChannelHandler] handler )
    Detach__INetChannelHandler_PacketEnd( [INetChannelHandler] handler )
    
    -- INetChannelHandler::FileRequested( [INetChannelHandler] handler, [string] filename, [number] transferID )
    Attach__INetChannelHandler_FileRequested( [INetChannelHandler] handler )
    Detach__INetChannelHandler_FileRequested( [INetChannelHandler] handler )
    
    -- INetChannelHandler::FileReceived( [INetChannelHandler] handler, [string] filename, [number] transferID )
    Attach__INetChannelHandler_FileReceived( [INetChannelHandler] handler )
    Detach__INetChannelHandler_FileReceived( [INetChannelHandler] handler )
    
    -- INetChannelHandler::FileDenied( [INetChannelHandler] handler, [string] filename, [number] transferID )
    Attach__INetChannelHandler_FileDenied( [INetChannelHandler] handler )
    Detach__INetChannelHandler_FileDenied( [INetChannelHandler] handler )
    
    -- PreProcessMessages( [CNetChan] netchan, [sn3_bf_read] messages )
      -- Optional return of new sn3_bf_read size in bits (incase you've tweaked the data)
    Attach__CNetChan_ProcessMessages()
    Detach__CNetChan_ProcessMessages()
    Metatables:

    Code:
    sn3_bf_write:
    
    	-- Data pointer
    	GetBasePointer() [UCHARPTR]
    	
    	-- Max number of bits that can be written
    	GetMaxNumBits() [number]
    	
    	-- Number of bits written
    	GetNumBitsWritten() [number]
    	
    	-- Number of bytes written
    	GetNumBytesWritten() [number]
    	
    	-- Number of bits remaining
    	GetNumBitsLeft() [number]
    	
    	-- Number of bytes remaining
    	GetNumBytesLeft() [number]
    	
    	-- Overflow status
    	IsOverflowed() [boolean]
    	
    	-- Seeks to specified bit
    	Seek( [number] bit )
    	
    	-- Writes ang in specified bits
    	WriteBitAngle( [number] ang, [number] bits )
    	
    	-- Writes a UCHARPTR in specified bits, returns success
    	WriteBits( [UCHARPTR] data, [number] bits ) [boolean]
    	
    	-- Writes a Vector coordinate
    	WriteBitVec3Coord( [Vector] vec )
    	
    	-- Writes a byte
    	WriteByte( [number] val )
    	
    	-- Writes a UCHARPTR in specified bytes
    	WriteBytes( [UCHARPTR] data, [number] bytes )
    	
    	-- Writes a character
    	WriteChar( [number] val )
    	
    	-- Writes a float
    	WriteFloat( [number] val )
    	
    	-- Writes a long
    	WriteLong( [number] val )
    	
    	-- Writes a single bit ( 1 or 0 )
    	WriteOneBit( [number] val )
    	
    	-- Writes a short
    	WriteShort( [number] val )
    	
    	-- Writes a null-terminated string
    	WriteString( [string] str )
    	
    	-- Writes a signed long value in specified bits
    	WriteSBitLong( [number] val, [number] bits )
    	
    	-- Writes an unsigned long value in specified bits
    	WriteUBitLong( [number] val, [number] bits )
    	
    	-- Writes a word
    	WriteWord( [number] val )
    	
    	-- Deletes bitbuf (Only call this if you allocated the buffer)
    	FinishWriting()
    	
    sn3_bf_read:
    
    	-- Data pointer
    	GetBasePointer() [UCHARPTR]
    	
    	-- Number of bits remaining
    	GetNumBitsLeft() [number]
    	
    	-- Number of bytes remaining
    	GetNumBytesLeft() [number]
    	
    	-- Number of bits read
    	GetNumBitsRead() [number]	
    	
    	-- Overflow status
    	IsOverflowed() [boolean]
    	
    	-- Reads an angle
    	ReadBitAngle( [number] bits ) [number]
    	
    	-- Reads angle object
    	ReadBitAngles() [Angle]
    	
    	-- Reads bits (Always call :Delete when finished with the result)
    	ReadBits( [number] bits ) [UCHARPTR]
    	
    	-- Reads a Vector coordinate
    	ReadBitVec3Coord() [Vector]
    	
    	-- Reads a byte
    	ReadByte() [number]
    	
    	-- Reads specified amount of bytes (Always call :Delete when finished with the result)
    	ReadBytes( [number] bytes ) [UCHARPTR]
    	
    	-- Reads a character
    	ReadChar() [number]
    	
    	-- Reads a float
    	ReadFloat() [number]
    	
    	-- Reads a long
    	ReadLong() [number]
    	
    	-- Reads a single bit ( 1 or 0 )
    	ReadOneBit() [number]
    	
    	-- Reads a short
    	ReadShort() [number]
    	
    	-- Reads a string (max 1024)
    	ReadString() [string]
    	
    	-- Reads a signed long value of length 'bits'
    	ReadSBitLong( [number] bits ) [number]
    	
    	-- Reads an unsigned long value of length 'bits'
    	ReadUBitLong( [number] bits ) [number]
    	
    	-- Reads a word
    	ReadWord() [number]
    	
    	-- Seeks to specified bit
    	Seek( [number] bit ) [boolean]
    	
    	-- Seeks to specified bit relative to current position
    	SeekRelative( [number] bit ) [boolean]
    	
    	-- Total bytes available
    	TotalBytesAvailable() [number]
    
    	-- Deletes bitbuf (Only call this if you allocated the buffer)
    	FinishReading()
    	
    CNetChan:
    
    	-- Prints registered net messages to console (debugging)
    	DumpMessages()
    
    	-- Resets buffers and a few other member variables
    	Reset()
    
    	-- Appears to purge fragments, not documented
    	Clear()
    
    	-- Terminates the net channel with the specified reason
    	Shutdown( [string] reason )
    
    	-- Adds data in buffers to send queue
    	Transmit( [opt boolean] onlyreliable ) [boolean]
    
    	-- Sends a local file
    	SendFile( [string] filename, [number] transferid ) [boolean]
    
    	-- Reports file denial
    	DenyFile( [string] filename, [number] transferid )
    
    	-- Attempts to download specified file, returns transfer ID
    	RequestFile( [string] filename ) [number]
    
    	-- Size of outgoing queue for specified stream
    	GetOutgoingQueueSize( [number] stream ) [number]
    
    	-- Returns fragments at offset in outgoing stream queue
    	GetOutgoingQueueFragments( [number] stream, [number] offset ) [dataFragments_t]
    
    	-- Adds fragments to outgoing queue
    	QueueOutgoingFragments( [number] stream, [dataFragments_t] fragments )
    
    	-- Current incoming fragments
    	GetIncomingFragments( [number] stream ) [dataFragments_t]
    
    	-- Table of subchannels
    	GetSubChannels() [table: subchannel_t]
    
    	-- Outgoing data buffers
    	GetReliableBuffer() [sn3_bf_write]
    	GetUnreliableBuffer() [sn3_bf_write]
    	GetVoiceBuffer() [sn3_bf_write]
    
    	-- Handler used by net channel for select events
    	GetNetChannelHandler() [INetChannelHandler]
    
    	-- Remote address
    	GetAddress() [netadr_t]
    
    	-- Time since networking was initialized
    	GetTime() [number]
    
    	-- Current latency (RTT), more accurate but jittering
    	GetLatency( [number] flow ) [number]
    	
    	-- Average packet latency in seconds
    	GetAvgLatency( [number] flow ) [number]
    	
    	-- Average packet loss
    	GetAvgLoss( [number] flow ) [number]
    	
    	-- Average packet choke
    	GetAvgChoke( [number] flow ) [number]
    	
    	-- Data flow in bytes/sec
    	GetAvgData( [number] flow ) [number]
    	
    	-- Average packets/sec
    	GetAvgPackets( [number] flow ) [number]
    	
    	-- Total flow in/out in bytes
    	GetTotalData( [number] flow ) [number]
    	
    	-- Last send sequence number
    	GetSequenceNr( [number] flow ) [number]
    	
    	-- true if packet was not lost/dropped/choked/flushed
    	IsValidPacket( [number] flow, [number] frame_number ) [boolean]
    	
    	-- Time when packet was sent
    	GetPacketTime( [number] flow, [number] frame_number ) [number]
    	
    	-- Group size of this packet
    	GetPacketBytes( [number] flow, [number] frame_number, [number] group ) [number]
    	
    	-- TCP progress if transmitting
    	GetStreamProgress( [number] flow ) [number;received, number;total]
    	
    	--
    	GetCommandInterpolationAmount( [number] flow, [number] frame_number ) [number]
    	
    	--
    	GetPacketResponseLatency( [number] flow, [number] frame_number ) [number;latencymsecs, number;choke]
    	
    	--
    	GetRemoteFramerate() [number;frametime, number;frametimedev]
    
    	--
    	SetInterpolationAmount( [number] amount )
    	
    	--
    	SetRemoteFramerate( [number] frametime, [number] frametimedev )
    
    	-- Sets max size for the reliable, unreliable or voice buffer
    	SetMaxBufferSize( [boolean] reliable, [number] bytes, [boolean] voice )
    
    	-- Is this a demo playback channel?
    	IsPlayback() [boolean]
    
    	-- Amount of seconds the net channel can go without communicating
    	GetTimeoutSeconds() [number]
    	SetTimeoutSeconds( [number] seconds )
    
    	-- The value of GetTime() when the channel was initialized
    	GetConnectTime() [number]
    	SetConnectTime( [number] t )
    
    	-- The value of GetTime() when the last packet was received
    	GetLastReceivedTime() [number]
    	SetLastReceivedTime( [number] t )
    
    	-- Channel name
    	GetName() [string]
    	SetName( [string] name )
    
    	-- Max bytes/sec the host can receive data
    	GetRate() [number]
    	SetRate( [number] val )
    
    	-- Background mode reduces the amount of data sent at once for certain operations, eg. file transfer
    	GetBackgroundMode() [boolean]
    	SetBackgroundMode( [boolean] state )
    
    	-- Use lz compression on game packets
    	GetCompressionMode() [boolean]
    	SetCompressionMode( [boolean] state )
    
    	-- Requested max packet size before packets are 'split'
    	GetMaxRoutablePayloadSize() [number]
    	SetMaxRoutablePayloadSize( [number] bytes )
    	
    subchannel_t:
    
    	-- Offset of fragment to be sent by subchannel
    	GetFragmentOffset( [number] stream ) [number]
    	SetFragmentOffset( [number] stream, [number] offset )
    
    	-- Amount of fragments to be sent by subchannel
    	GetFragmentNumber( [number] stream )
    	SetFragmentNumber( [number] stream, [number] num )
    
    	-- Outgoing sequence at time of sending
    	GetSequence() [number]
    	SetSequence( [number] seq )
    	
    	-- Current state of subchannel ( 0 = idle, 1 = needs sending, 2 = ready?, 3 = ? )
    	GetState() [number]
    	SetState( [number] state )
    
    	-- Subchannel index (0-7)
    	GetIndex() [number]
    	SetIndex( [number] index )
    	
    dataFragments_t:
    
    	-- Handle for file operations
    	GetFileHandle() [FileHandle_t]
    	SetFileHandle( [FileHandle_t] handle )
    	
    	-- File name
    	GetFileName() [string]
    	SetFileName( [string] filename )
    	
    	-- File transfer ID
    	GetFileTransferID() [number]
    	SetFileTransferID( [number] id )
    	
    	-- Data buffer
    	GetBuffer() [UCHARPTR]
    	SetBuffer( [UCHARPTR] buf )
    	
    	-- Data size (bytes)
    	GetBytes() [number]
    	SetBytes( [number] bytes )
    	
    	-- Data size (bits)
    	GetBits() [number]
    	SetBits( [number] bits )
    	
    	-- Actual size (for compression)
    	GetActualSize() [number]
    	SetActualSize( [number] bytes )
    	
    	-- Check for compression
    	GetCompressed() [boolean]
    	SetCompressed( [boolean] state )
    	
    	-- Check for stream usage
    	GetStream() [boolean]
    	SetStream( [boolean] state )
    	
    	-- Total number of fragments to be sent
    	GetTotal() [number]
    	SetTotal( [number] total )
    	
    	-- Amount of fragments sent so far
    	GetProgress() [number]
    	SetProgress( [number] progress )
    	
    	-- Amount of fragments to send in next packet
    	GetNum() [number]
    	SetNum( [number] num )
    	
    	-- Cleanup self-allocated fragments
    	Delete()
    	
    FileHandle_t:
    
    	-- Empty
    
    UCHARPTR:
    
    	-- Cleanup self-allocated data
    	Delete()
    
    netadr_t:
    
    	IsLocalhost() [boolean]
    	IsLoopback() [boolean]
    	IsReservedAdr() [boolean]
    	IsValid() [boolean]
    	GetIP() [number]
    	GetPort() [number]
    	GetType() [number]
    	ToString( [opt boolean] baseOnly ) [string]
    
    INetworkStringTableContainer:
    	
    	FindTable( [string] tablename ) [INetworkStringTable]
    	GetTable( [number] tableid ) [INetworkStringTable]
    
    INetworkStringTable:
    
    	GetString( [number] id ) [string]
    
    IGameEventManager2:
    
    	-- Call IGameEvent.Delete when done
    	CreateEvent( [string] name ) [IGameEvent]
    	-- Serializes an IGameEvent into buffer
    	SerializeEvent( [IGameEvent] event, [sn3_bf_write] buf ) [boolean]
    	-- Unserializes an event from a buffer
    	UnserializeEvent( [sn3_bf_read] buf ) [IGameEvent]
    
    IGameEvent:
    
    	-- Event name
    	GetName() [string]
    	-- If event handled reliably
    	IsReliable() [boolean]
    	-- If event is never networked
    	IsLocal() [boolean]
    	-- Check if data field exists
    	IsEmpty( [string] keyName ) [boolean]
    	-- Read access
    	GetBool( [string] keyName ) [boolean]
    	GetInt( [string] keyName ) [number]
    	GetFloat( [string] keyName ) [number]
    	GetString( [string] keyName ) [string]
    	-- Write access
    	SetBool( [string] keyName, [boolean] value )
    	SetInt( [string] keyName, [number] value )
    	SetFloat( [string] keyName, [number] value )
    	SetString( [string] keyName, [string] value )
    Constants:

    Code:
    [table] UpdateType
    {
    	[number] EnterPVS
    	[number] LeavePVS
    	[number] DeltaEnt
    	[number] PreserveEnt
    	[number] Finished
    	[number] Failed
    }
    
    [number] FHDR_ZERO
    [number] FHDR_LEAVEPVS
    [number] FHDR_DELETE
    [number] FHDR_ENTERPVS
    
    [string] INSTANCE_BASELINE_TABLENAME
    [string] LIGHT_STYLES_TABLENAME
    [string] USER_INFO_TABLENAME
    [string] SERVER_STARTUP_DATA_TABLENAME
    
    [number] DELTA_OFFSET_BITS
    [number] DELTA_OFFSET_MAX
    
    [number] DELTASIZE_BITS
    
    [number] NUM_NEW_COMMAND_BITS
    [number] MAX_NEW_COMMANDS
    
    [number] NUM_BACKUP_COMMAND_BITS
    [number] MAX_BACKUP_COMMANDS
    
    [number] NET_MESSAGE_BITS
    
    [number] net_NOP
    [number] net_Disconnect
    [number] net_File
    [number] net_LastControlMessage
    
    [number] net_Tick
    [number] net_StringCmd
    [number] net_SetConVar
    [number] net_SignonState
    
    [number] svc_ServerInfo
    [number] svc_SendTable
    [number] svc_ClassInfo
    [number] svc_SetPause
    [number] svc_CreateStringTable
    [number] svc_UpdateStringTable
    [number] svc_VoiceInit
    [number] svc_VoiceData
    [number] svc_Print
    [number] svc_Sounds
    [number] svc_SetView
    [number] svc_FixAngle
    [number] svc_CrosshairAngle
    [number] svc_BSPDecal
    [number] svc_UserMessage
    [number] svc_EntityMessage
    [number] svc_GameEvent
    [number] svc_PacketEntities
    [number] svc_TempEntities
    [number] svc_Prefetch
    [number] svc_Menu
    [number] svc_GameEventList
    [number] svc_GetCvarValue
    [number] svc_CmdKeyValues
    [number] SVC_LASTMSG
    
    [number] clc_ClientInfo
    [number] clc_Move
    [number] clc_VoiceData
    [number] clc_BaselineAck
    [number] clc_ListenEvents
    [number] clc_RespondCvarValue
    [number] clc_FileCRCCheck
    [number] clc_CmdKeyValues
    [number] clc_FileMD5Check
    [number] CLC_LASTMSG
    
    [number] RES_FATALIFMISSING
    [number] RES_PRELOAD
    
    [number] SIGNONSTATE_NONE
    [number] SIGNONSTATE_CHALLENGE
    [number] SIGNONSTATE_CONNECTED
    [number] SIGNONSTATE_NEW
    [number] SIGNONSTATE_PRESPAWN
    [number] SIGNONSTATE_SPAWN
    [number] SIGNONSTATE_FULL
    [number] SIGNONSTATE_CHANGELEVEL
    
    [number] MAX_STREAMS
    [number] FRAG_NORMAL_STREAM
    [number] FRAG_FILE_STREAM
    
    [number] MAX_RATE
    [number] MIN_RATE
    [number] DEFAULT_RATE
    
    [number] MAX_FRAGMENT_SIZE
    [number] MAX_SUBCHANNELS
    [number] MAX_FILE_SIZE
    
    [number] FLOW_OUTGOING
    [number] FLOW_INCOMING
    [number] MAX_FLOWS
    
    [number] MAX_CUSTOM_FILES
    Changes:

    http://code.google.com/p/christopherthorne/source/list
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Useful x 10Lua King x 8Winner x 3Zing x 1Dumb x 1 (list)

  2. Post #2
    CombineGuru's Avatar
    June 2009
    3,644 Posts
    looks good
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Agree Agree x 4Dumb Dumb x 2 (list)

  3. Post #3
    Gold Member
    Gbps's Avatar
    December 2008
    3,437 Posts
    I'll be releasing Files on Demand [soon], it uses sourcenet3.

    I'll update this post when it's released
    Reply With Quote Edit / Delete Reply United States Show Events Useful x 7Late x 4Friendly x 1Winner x 1Dumb x 1Optimistic x 1Informative x 1 (list)

  4. Post #4
    yakahughes's Avatar
    April 2008
    1,318 Posts
    Another freaking brilliant module. This probably means nothing coming from me, but well done.
    Reply With Quote Edit / Delete Reply United States Show Events Funny Funny x 3Lua King Lua King x 1Zing Zing x 1 (list)

  5. Post #5
    Gold Member
    Kill coDer's Avatar
    April 2006
    949 Posts
    Where can we find how the different messages are structured? Didn't valve have an online repository of the SDK code too? I can't find it..
    Reply With Quote Edit / Delete Reply Australia Show Events Lua Helper Lua Helper x 1 (list)

  6. Post #6
    likes men
    Python1320's Avatar
    May 2007
    1,727 Posts
    Thanks for the christmas present
    Reply With Quote Edit / Delete Reply Finland Show Events Agree Agree x 6 (list)

  7. Post #7
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Where can we find how the different messages are structured? Didn't valve have an online repository of the SDK code too? I can't find it..
    The messages aren't in the SDK. Take a look at sn3_base_netmessages.lua for structures.

  8. Post #8
    ColdFusion's Avatar
    December 2009
    2,045 Posts
    include( "sn3_base_incoming.lua" )
    local convar = CreateConVar("disconnect_msg", "Disconnect by user.")
    
    FilterOutgoingMessage( net_Disconnect, function( netchan, read, write )
    	write:WriteUBitLong( net_Disconnect, 6)
    	read:ReadString()
    	write:WriteString( convar:GetString() )
    end )
    Custom disconnect msg. aka change "SomeFaggot disconnected(Kicked by admin)" to "Somefaggot disconnected(Suck my donkey dick)"

    ( should probably say that you run this clientside, and that the people in the server see this when you disconnect.)


    Doesn't work. Because it detaches before the disconnect msg is send.
    Reply With Quote Edit / Delete Reply Netherlands Show Events Useful Useful x 3Funny Funny x 1 (list)

  9. Post #9
    Gold Member
    ralle105's Avatar
    October 2005
    4,400 Posts
    Am I just being stupid or could you not free the allocated objects in their __gc metamethod?

    Sweet module either way
    Reply With Quote Edit / Delete Reply Sweden Show Events Agree Agree x 3Friendly Friendly x 1 (list)

  10. Post #10
    Flapadar's Avatar
    June 2010
    569 Posts
    Awesome.

  11. Post #11
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Am I just being stupid or could you not free the allocated objects in their __gc metamethod?

    Sweet module either way
    That would cause objects passed as arguments to be deleted when they shouldn't be + there's not really any reason to use the garbage collector.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Informative Informative x 2 (list)

  12. Post #12
    Gold Member
    LuaStoned's Avatar
    September 2007
    1,300 Posts
    Really awesome, can't wait to mess with it :D
    Reply With Quote Edit / Delete Reply Austria Show Events Agree Agree x 4Funny Funny x 1 (list)

  13. Post #13
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    include( "sn3_base_incoming.lua" )
    local convar = CreateConVar("disconnect_msg", "Disconnect by user.")
    
    FilterOutgoingMessage( net_Disconnect, function( netchan, read, write )
    	write:WriteUBitLong( net_Disconnect, 6)
    	read:ReadString()
    	write:WriteString( convar:GetString() )
    end )
    Custom disconnect msg. aka change "SomeFaggot disconnected(Kicked by admin)" to "Somefaggot disconnected(Suck my donkey dick)"

    ( should probably say that you run this clientside, and that the people in the server see this when you disconnect.)


    Doesn't work. Because it detaches before the disconnect msg is send.
    Code:
    require( "sourcenet3" )
    
    local buf = CNetChan():GetReliableBuffer()
    
    buf:WriteUBitLong( net_Disconnect, 6 )
    buf:WriteString( "Bye!" )
    
    CNetChan():Transmit()
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Agree Agree x 1Informative Informative x 1Useful Useful x 1 (list)

  14. Post #14
    q3k
    Gold Member
    q3k's Avatar
    October 2009
    919 Posts
    Finally, a Linux binary.
    Reply With Quote Edit / Delete Reply Poland Show Events Agree Agree x 2 (list)

  15. Post #15
    Nexus435's Avatar
    July 2010
    1,414 Posts
    -snip-
    Reply With Quote Edit / Delete Reply United States Show Events Disagree Disagree x 3 (list)

  16. Post #16
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    I've fixed some problems in the base code for the next revision, however I'm having trouble with hooking since the last engine update. Currently looking into it.

  17. Post #17
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Fixed. The problem was caused by GetData returning a pointer at a byte offset, which caused problems when the previous data (before the net messages) wasn't a set of complete bytes.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Funny Funny x 1 (list)

  18. Post #18
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    Quick question. As per Chris' code above, it is possible to detect the disconnect msg a player would normally transmit, and modify it as you want, however is it possible to modify the player's name as well?

    SomePerson disconnected (random reason)
    Becomes
    SpecificPerson disconnected (reason to be determined)
    Also, how would you read what a user's disconnect reason was and respond to it?

  19. Post #19
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Quick question. As per Chris' code above, it is possible to detect the disconnect msg a player would normally transmit, and modify it as you want, however is it possible to modify the player's name as well?


    Becomes


    Also, how would you read what a user's disconnect reason was and respond to it?
    To modify the player name you would have to hook the svc_GameEvent message (outgoing), but I haven't added a wrapper for that yet. As for reading and responding, you can probably just add an incoming filter for the net_Disconnect message using the base code.

  20. Post #20
    taste the salty dong
    Remscar's Avatar
    September 2009
    1,715 Posts
    At first i thought the addon was gm_skynet3

    Excellent Module.
    Reply With Quote Edit / Delete Reply United States Show Events Funny Funny x 8 (list)

  21. Post #21
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Quick question. As per Chris' code above, it is possible to detect the disconnect msg a player would normally transmit, and modify it as you want, however is it possible to modify the player's name as well?


    Becomes


    Also, how would you read what a user's disconnect reason was and respond to it?
    I've added the necessary functions to parse game events in revision 6.

    include( "sn3_base_gameevents.lua" )
    
    hook.Add( "SendGameEvent", "ChangeReason", function( netchan, event )
    	if ( event:GetName() != "player_disconnect" ) then return end
    
    	local reason = event:GetString( "reason" )
    
    	if ( reason == "Disconnect by user." ) then
    		event:SetString( "reason", "Disconnected after " .. math.floor( netchan:GetTime() - netchan:GetConnectTime() ) .. " seconds" )
    	
    		return event
    	end
    end )

    The name displayed is calculated using the "userid" key, so it won't be as easy to change.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Friendly Friendly x 2 (list)

  22. Post #22
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    Would it be possible to combine this with the normal user disconnect hook? Use sourcenet to find the reason for the disconnect, and pass the string off to the player.disconnect hook to display whatever you want?

    Does this take place prior to the player.disconnect hook?

  23. Post #23
    Nexus435's Avatar
    July 2010
    1,414 Posts
    Would it be possible to combine this with the normal user disconnect hook? Use sourcenet to find the reason for the disconnect, and pass the string off to the player.disconnect hook to display whatever you want?

    Does this take place prior to the player.disconnect hook?
    Code:
    require( "sourcenet3" )
    
    local buf = CNetChan():GetReliableBuffer()
    
    buf:WriteUBitLong( net_Disconnect, 6 )
    buf:WriteString( "Bye!" )
    
    CNetChan():Transmit()

  24. Post #24
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    Where are you reading the reason they disconnected in there?

    If the hook chris used above gets executed before the player.disconnect hook, then I can just assign the reason to a var and read it in the disconnect hook. Then I can print out whatever I want, in addition to the reason.

    What I am trying to do is alter the player's name, but keep the reason intact. Also, it would be cool to respond to reasons, but with chris's example above, I can do that. I only need to know which hook is executed first. I can experiment, but I don't have access to gmod at the moment.

  25. Post #25
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    include( "sn3_base_incoming.lua" )
    
    FilterIncomingMessage( net_Disconnect, function( netchan, read, write )
    	local reason = read:ReadString()
    
    	write:WriteUBitLong( net_Disconnect, 6 )
    	write:WriteString( string.reverse( reason ) )
    end )

    Client "Chrisaster" connected (192.168.1.9:27006).
    Dropped Chrisaster from server (.resu yb tcennocsiD)
    This will change what the server sees the reason as too. Use the previous example if you just want to change what other clients are sent.

    Edited:

    This won't work if you kick the user.

  26. Post #26
    PC Camp's Avatar
    July 2007
    363 Posts
    im not sure if i understand what this does exactly, but it seems like its pretty useful. lol i think its used to transfer data from the client and server.

    anyone wanna give me an example on how to use this? lol

  27. Post #27
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    im not sure if i understand what this does exactly, but it seems like its pretty useful. lol i think its used to transfer data from the client and server.

    anyone wanna give me an example on how to use this? lol
    There's a variety of examples included in the download.

  28. Post #28
    q3k
    Gold Member
    q3k's Avatar
    October 2009
    919 Posts
    So I tried to use the module on my Linux srcds today...
    Code:
    error loading module 'sourcenet3' from file '/home/srcds/orangebox/garrysmod/lua/includes/modules/gm_sourcenet3_linux.dll':
            /home/srcds/orangebox/garrysmod/lua/includes/modules/gm_sourcenet3_linux.dll: undefined symbol: META_IGameEventManager2_name

  29. Post #29
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    So I tried to use the module on my Linux srcds today...
    Code:
    error loading module 'sourcenet3' from file '/home/srcds/orangebox/garrysmod/lua/includes/modules/gm_sourcenet3_linux.dll':
            /home/srcds/orangebox/garrysmod/lua/includes/modules/gm_sourcenet3_linux.dll: undefined symbol: META_IGameEventManager2_name
    My bad, I forgot to add the new obj files to the makefile. I'll fix it now.

    Edited:

    Fixed.

  30. Post #30
    Skull435's Avatar
    October 2009
    77 Posts
    Possible to get a function for the CRC check?

  31. Post #31
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Possible to get a function for the CRC check?
    What?

  32. Post #32
    Skull435's Avatar
    October 2009
    77 Posts
    [ clc_FileCRCCheck ] = { -- 14 (Untested)
    			DefaultCopy = function( netchan, read, write )
    				write:WriteUBitLong( clc_FileCRCCheck, 6 )
    				
    				local unk1 = read:ReadOneBit()
    				write:WriteOneBit( unk1 )
    				
    				local gamepath = read:ReadUBitLong( 2 )
    				write:WriteUBitLong( gamepath, 2 )
    				
    				local unk3
    
    				write:WriteUBitLong( clc_FileCRCCheck, 6 )
    				
    				local unk1 = read:ReadOneBit()
    				write:WriteOneBit( unk1 )
    				
    				local gamepath = read:ReadUBitLong( 2 )
    				write:WriteUBitLong( gamepath, 2 )
    				
    				local unk3
    
    				if ( gamepath == 0 ) then
    					unk3 = read:ReadString() -- 10h
    					write:WriteString( unk3 )
    				end
    				
    				local unk4 = read:ReadUBitLong( 3 )
    				write:WriteUBitLong( unk4, 3 )
    				
    				local filename = read:ReadString()
    				write:WriteString( filename )
    				
    				local unk6 = read:ReadUBitLong( 32 )
    				write:WriteUBitLong( unk6, 32 )
    	
    				debugprint( "FileCRCCheck", unk1, gamepath, unk3, unk4, filename, unk6 )
    			end
    		},
    
    Possible to use this netmessage?
    Reply With Quote Edit / Delete Reply United States Show Events Funny Funny x 1 (list)

  33. Post #33
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Possible to use this netmessage?
    I'll look into it.

    Edited:

    That base code is really wrong (it writes the type twice), not sure how that happened.

    Edited:

    Fixed. I'm fairly sure the message is only used for sv_pure servers, so I'll have to find out how the server requests files to be checked.

  34. Post #34
    Map in a box's Avatar
    July 2009
    5,785 Posts
    This video should just about sum my thoughts up:
    Reply With Quote Edit / Delete Reply United States Show Events Optimistic Optimistic x 2Late Late x 1Dumb Dumb x 1 (list)

  35. Post #35
    Gold Member
    slayer3032's Avatar
    November 2007
    2,390 Posts
    There is an example to remove client ip's from being sent to other clients in game events.

    This module is amazing.
    Reply With Quote Edit / Delete Reply United States Show Events Agree Agree x 1 (list)

  36. Post #36
    Athos's Avatar
    July 2007
    87 Posts
    For some reason, whenever I try to create a game (Single or Multiplayer) I'm disconnected...
    Here what is returned in console:

    Predicted index for loopback = 1
    Attach: CNetChan_Shutdown
    Attach: CNetChan_ProcessMessages
    Attach: CNetChan_SendDatagram
    Attach: CNetChan_ProcessPacket
    Unknown Incoming Message: 32
    Interval_per_tick -4617235029629060700000000.000000 out of range [0.001000 to 0.100000]
    Detach: CNetChan_Shutdown
    Detach: CNetChan_ProcessMessages
    Detach: CNetChan_SendDatagram
    Detach: CNetChan_ProcessPacket
    Dropped Athos from server (Disconnect by user.)

  37. Post #37
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    For some reason, whenever I try to create a game (Single or Multiplayer) I'm disconnected...
    Here what is returned in console:
    Do you have the latest version installed?

    Edited:

    Including the base code.

    Edited:

    I can't recreate it on my server.

  38. Post #38
    Athos's Avatar
    July 2007
    87 Posts
    Yep, gm_sourcenet3 r6b

    I put all the example files in lua/autorun
    but even with only basic files it still happens

  39. Post #39
    IS AWESOME@@@@@@@@@@

    January 2009
    967 Posts
    Yep, gm_sourcenet3 r6b

    I put all the example files in lua/autorun
    but even with only basic files it still happens
    It seems to be a listen server problem - I'll see what I can do about it.

  40. Post #40
    Gold Member
    Kill coDer's Avatar
    April 2006
    949 Posts
    With respect to the VoiceData example, is it possible to grab the data on the server, send it with sockets in binary mode to another server then send it to all clients?

    The issue I'm having is that I don't know how to get the server to send the mic chat to the clients on the other end. Will I have to create fake player objects? Or is it possible to stream the VoiceData with gm_bass?