• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

WarSocAPI

Status
Not open for further replies.

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
JASS:
//============================================================================
// WarSocAPI - v2.00
native SocStart			takes nothing								returns boolean
native SocExit			takes nothing								returns boolean
native SocTCPConnect		takes string ip, integer port, integer mode				returns integer
native SocTCPListen		takes integer port, integer maxqueue, integer mode 			returns integer
native SocTCPAccept		takes integer socket, integer mode					returns integer
native SocTCPIP			takes integer socket							returns string
native SocSetNagle		takes integer socket, boolean on					returns integer
native SocTCPConnected		takes integer socket							returns boolean
native SocUDPConnect		takes integer port, integer mode					returns integer
native SocSendUDPMessage 	takes integer udpsocket, string ip, integer port, integer buffer 	returns integer
native SocSendTCPMessage 	takes integer tcpsocket, integer buffer 				returns integer
native SocReceiveMessage 	takes integer socket, integer length, integer buffer 			returns integer
native SocPeekMessage		takes integer socket, integer length, integer buffer 			returns integer
native SocGetLastInIP		takes nothing								returns string
native SocGetLastInPort		takes nothing								returns integer
native SocSetSync		takes integer socket, integer mode					returns integer
native SocCloseSocket		takes integer socket							returns boolean
native SocGetSocketLastError 	takes integer socket							returns integer
native SocGetMyHost		takes nothing								returns string
native SocCompareIp		takes string ip, string mask						returns boolean
native SocBufferWriteByte 	takes integer val, integer buffer					returns integer
native SocBufferWriteShort 	takes integer val, integer buffer					returns integer
native SocBufferWriteUShort 	takes integer val, integer buffer					returns integer
native SocBufferWriteInt 	takes integer val, integer buffer					returns integer
native SocBufferWriteUInt 	takes integer val, integer buffer					returns integer
//native SocBufferWriteFloat 	takes real val, integer buffer						returns integer
native SocBufferReadByte 	takes integer buffer							returns integer
native SocBufferReadShort 	takes integer buffer							returns integer
native SocBufferReadUShort 	takes integer buffer							returns integer
native SocBufferReadInt 	takes integer buffer							returns integer
native SocBufferReadUInt 	takes integer buffer							returns integer
//native SocBufferReadFloat 	takes integer buffer							returns real
native SocBufferWriteString 	takes string str, integer buffer					returns integer
native SocBufferReadString 	takes integer buffer							returns string
native SocBufferClear		takes integer buffer							returns boolean
native SocBufferSize 		takes integer buffer							returns integer
native SocBufferCreate		takes nothing								returns integer
native SocBufferDestroy 	takes integer buffer							returns integer
native SocBufferCopy		takes integer bufferdestination, integer buffersource			returns integer
native SocMacAddress		takes nothing								returns string
native MD5			takes string s								returns string
native SocBufferMD5		takes integer buffer							returns string
native SocBufferExists		takes integer buffer							returns boolean
native SocNetConnected		takes nothing								returns boolean

native SocBufferWriteOrderID 	takes integer val, integer buffer					returns integer
native SocBufferReadOrderID 	takes integer buffer							returns integer

Tutorial: N/A
Download: N/A
Native Set Type: Single Player
Release: 0.10
Other: N/A
 
Last edited:
Level 5
Joined
Jun 28, 2005
Messages
108
hmmmm.... it's very interesting... ^^
it's stable ? have you tested it etc. cause i have LAN at so i could make some test (if needed) + i am self interested in such things...

gj i will test it ! =)
// well cool stuff what you have here =) +1
 

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
It has been tested a lot, and so far there has been no problems. Only thing worth mentioning is that SocSendTCPMessage has shown some speed issues, but I'm working on a way around that so it wont be sending a lot of messages, but rather one big one with all the data, which should actually end up saving a few bytes of data in the long run. The only problem with doing that is that the engine will be more vulnerable to packet losses since instead of only a little data lost, it might be a lot of data.
 
Level 11
Joined
Aug 25, 2006
Messages
971
Looks like Winsoc on crack.
Could you explain the usage of the following:
JASS:
native SocTCPIP takes integer socket //Sets ip? For what?
native SocSetNagle takes integer socket, boolean on //?!
native SocPeekMessage takes integer socket, integer length, integer buffer //Looks at message without clearing from buffer?
native SocBufferReadByte takes integer buffer //What does this do compared to SocReceiveMessage
native SocBufferWriteOrderID takes integer val, integer buffer returns integer //The order of what?
native SocBufferReadOrderID takes integer buffer //?
native MD5 takes string s returns string //? Isn't MD5 an encryption?
native SocBufferMD5 takes integer buffer //?
native SocBufferWriteByte takes integer val, integer buffer //What does this do compared to SocSendTCPMessage
native SocCompareIp takes string ip, string mask //Compare to what?
native SocBufferDestroy takes integer buffer //Whats the point of creating/destroying your buffer? Shouldn't it always exist?
I'm thinking about using this to create multiplayer for my FPS. This is because all camera movements use GetLocalPlayer or they are global. This causes a high chance of d/c. Also it could never really work on bnet because people would need to use RTC just to run it.

This doesn't seem to support more then one connection. If this pans out I'll go build a server in VB. (I know how to use winsock, at least in VB)
 

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
Looks like Winsoc on crack.
Could you explain the usage of the following:
JASS:
native SocTCPIP takes integer socket //Sets ip? For what?
native SocSetNagle takes integer socket, boolean on //?!
native SocPeekMessage takes integer socket, integer length, integer buffer //Looks at message without clearing from buffer?
native SocBufferReadByte takes integer buffer //What does this do compared to SocReceiveMessage
native SocBufferWriteOrderID takes integer val, integer buffer returns integer //The order of what?
native SocBufferReadOrderID takes integer buffer //?
native MD5 takes string s returns string //? Isn't MD5 an encryption?
native SocBufferMD5 takes integer buffer //?
native SocBufferWriteByte takes integer val, integer buffer //What does this do compared to SocSendTCPMessage
native SocCompareIp takes string ip, string mask //Compare to what?
native SocBufferDestroy takes integer buffer //Whats the point of creating/destroying your buffer? Shouldn't it always exist?
I'm thinking about using this to create multiplayer for my FPS. This is because all camera movements use GetLocalPlayer or they are global. This causes a high chance of d/c. Also it could never really work on bnet because people would need to use RTC just to run it.

This doesn't seem to support more then one connection. If this pans out I'll go build a server in VB. (I know how to use winsock, at least in VB)

native SocTCPIP takes integer socket //Sets ip? For what?
Doesn't set the IP, it gets the IP of a socket.

native SocSetNagle takes integer socket, boolean on //?!
Turns on/off the naggle (TCP_NODELAY) algorithm. I don't remember exactly what it's for, i never use it.
http://en.wikipedia.org/wiki/Nagle's_algorithm

native SocPeekMessage takes integer socket, integer length, integer buffer //Looks at message without clearing from buffer?
Exactly

native SocBufferReadByte takes integer buffer //What does this do compared to SocReceiveMessage
This reads a byte from a Buffer, SocReceiveMessage is used to receive a buffer to read from.

native SocBufferWriteOrderID takes integer val, integer buffer returns integer //The order of what?
native SocBufferReadOrderID takes integer buffer //?
OrderID is a units order ID, used to save bytes on buffers because it converts a range of common orders into two bytes rather than four.

native MD5 takes string s returns string //? Isn't MD5 an encryption?
Yes, it's part of the WarSocAPI by coincidence and used by the native below
native SocBufferMD5 takes integer buffer //?
Used to create an MD5 hash of a buffers contents, useful for checking if a buffer has be changed in any way.

native SocBufferWriteByte takes integer val, integer buffer //What does this do compared to SocSendTCPMessage
Read the part about SocBufferReadByte

native SocCompareIp takes string ip, string mask //Compare to what?
Compares and IP to a mask, for example:
82.192.160.50 compared to 82.192.*.* would be true
while
82.192.160.50 compared to 82.193.*.* would be false

native SocBufferDestroy takes integer buffer //Whats the point of creating/destroying your buffer? Shouldn't it always exist?
Buffers is what is sent through the sockets, they're the key to data transfer. I most cases one buffer would be enough, but sometimes you need more. In my WIP demo, i have a buffer for receiving and sending, so i'm sure they'll never have a collision and write to the same buffer.
This doesn't seem to support more then one connection. If this pans out I'll go build a server in VB. (I know how to use winsock, at least in VB)
Sockets is the way you have multiple connections. Sockets can be compared to pipes, they're what connect you to the other end. You can have as many pipes as you want, to wherever you want.
 
Level 2
Joined
Jan 3, 2006
Messages
6
Hi there. You did a very good job. That was what i searching for last 3-4years. Im planning to create a MMORPG based on War3, where player could switch locations etc etc, unlimited players. Well, i have a questions of using Buffersocket.

Well, i tried this:
Code:
native SocBufferReadString 	takes integer buffer							returns string
and made some ingame outputs, that happens every 1 sec:

Code:
    call DisplayTextToForce(GetPlayersAll(),"0:"+I2S(SocReceiveMessage(udg_ConnectedSocket,500,udg_Buffer)))
    call DisplayTextToForce(GetPlayersAll(),"1:"+(SocBufferReadString(udg_Buffer) ))
    call DisplayTextToForce(GetPlayersAll(),"2:"+I2S(SocBufferSize(udg_Buffer)) )
    call DisplayTextToForce(GetPlayersAll(),"3:"+I2S(SocBufferReadShort(udg_Buffer)) )
    call DisplayTextToForce(GetPlayersAll(),"4:"+I2S(SocBufferReadUShort(udg_Buffer)) )
    call DisplayTextToForce(GetPlayersAll(),"5:"+I2S(SocBufferReadInt(udg_Buffer)) )
    call DisplayTextToForce(GetPlayersAll(),"6:"+I2S(SocBufferReadUInt(udg_Buffer)) )
    call DisplayTextToForce(GetPlayersAll(),"7:"+I2S(SocBufferReadByte(udg_Buffer)) )
And the second one(ReadString) doesnt works, and always is blank, also when im sending message from another socked... Can you give some advantage to me please?
Well, it will be good, if you make a some descriptions to several functions, b/c im not using c++ or vb, so its some problematic for me to understand all functions. You said that you made a map with working chat, but unfortunately i have not founded it :(.
 

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
Due to lack of any real tutorial yet, since i'm still working on it, i have a map here, that uses the functions, and works to have one player connect to another. I hope it suffices for your needs sofar. I'm sorry i can't be of much more help, but explaining how WarSoc works, would be like writing the whole tutorial in one post.

One advice tho.
SocReceiveMessage(udg_ConnectedSocket,500,udg_Buffer)
instead use this
SocReceiveMessage(udg_ConnectedSocket,0,udg_Buffer)
which receives everything instead of just 500 bytes.

Also, SocReceiveMessage returns a number larger than 0 if it actually received something, so usage like this is optimal
JASS:
if(SocReceiveMessage(udg_ConnectedSocket,0,udg_Buffer) > 0) then
    //do stuff
endif
 

Attachments

  • WarSoc Proff of Concept Space Map.w3x
    577.1 KB · Views: 248
Status
Not open for further replies.
Top