This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
billysback's profile picture

[API] multinet - multi-user just got easier!

Started by billysback, 24 November 2012 - 07:51 AM
billysback #1
Posted 24 November 2012 - 08:51 AM
Multinet

Lets cut to the chase, functions:
Spoiler

createServer(name, id)
   -creates and returns a server with that name using that computer id (just use os.computerID())
createUser(user_name, server_name, user_id, server_id)
   -creates and returns a user for that server (along with id) using that username and that user_id (just use of.computerID())
getServers()
   -returns a list of all multinet servers in format: [servername] = id

Now here are the server functions:
Spoiler

server:getPlayerList()
   -returns a normal table (1 to length) containing all player names
server:sendPlayerList(playername)
   -sends the playerlist to that user
server:getUsers()
   -returns a table containing [playername] = id
server:removePlayer(playername)
   -removes a player from the server's playerlist
server:addPlayer(playername, playerid, data)
   -adds a player with that playername, playerid and data (data is a table)
server:removePlayer(playername)
   -removes a player with that playername
server:addSData(name, info)
   -adds some data to the server ([name] = info)
server:getSData()
   -returns the server data formated.
server:getPlayer(id)
   -returns the playername matching that id
server:getID(player)
   -returns the id matching that playername
server:setData(player, data)
   -sets the players data to that data (is a table)
server:getData(player, data)
   -returns the players data unformated.
server:pingUsers(info)
  -sends that string (info) to all of the users
server:waitForCommand()
  -waits until it receives a command over rednet, returns the type of command
  -Types:
     nil = an error happened, this shouldn't happen
     "INVALID" = invalid command or command went wrong
     1 = player joined
     2 = player leaved
     3 = sent user data to user
     4 = sent player list to user
     5 = sent the name of the server
     6 = sent server data to player
     7 = user set server data
     8 = user set user data, 11 if failed

variables:

server.name
   -the servers name
server.id
   -the servers id
server.users
   -the servers user ([playername] = id)
server.data
   -the servers data (any)

Now here are the user functions:
Spoiler

user:joinServer()
   -joins the server
user:leaveServer()
  -leaves the server
user:getPlayerList()
  -returns the playerlist
user:getData()
  -returns the user's data
user:setData()
  -sets the user's data
user:getSData()
   -returns the server's data
user:setSData(name, piece)
   -sets that server data
user:waitForPing()
   -waits for a rednet message, returns message if it was from the server or nil if it wasn't
user:isFromServer(id)
   -returns true if id matches the server's id, false if it doesn't

variables:

user.name
   -returns the user's name
user.id
  -returns the user's id
user.server_name
   -returns the server's name
user.server_id
  -returns the server's id

Download:
Spoilerhttp://pastebin.com/WGCM34TP

Example:
Spoilerhttp://www.computercraft.info/forums2/index.php?/topic/6361-irc-multinet-example/
billysback #2
Posted 24 November 2012 - 11:41 PM
Update;
just bug fixes… I think.
billysback #3
Posted 25 November 2012 - 01:32 AM
Updated;
getting player list fixed, maybe some other bug fixes (I forget…)
ElectricOverride #4
Posted 25 November 2012 - 03:34 AM
Uhm, sorry for being a noob but I dont actually know how to install APIs. :D/>/>
billysback #5
Posted 25 November 2012 - 03:36 AM
If you download the latest version of navy it should do it for you, otherwise do:

pastebin get WGCM34TP multinet
also, you may need to do:

lua
os.loadAPI("multinet")
exit
ElectricOverride #6
Posted 25 November 2012 - 03:38 AM
If you download the latest version of navy it should do it for you, otherwise do:
 pastebin get WGCM34TP multinet 
also, you may need to do:
 lua os.loadAPI("multinet") exit 
Okay, thanks for the help!
tommyroyall #7
Posted 26 November 2012 - 08:54 AM
This is awesome man :D/>/>.
tommyroyall #8
Posted 26 November 2012 - 09:15 AM
Also, lacking documentation? Like, server:waitForCommand(), what is the type that it returns?
billysback #9
Posted 26 November 2012 - 10:40 AM
Oh, yeah.
I'll add the types now :P/>
worldmc #10
Posted 07 December 2012 - 11:53 PM
so this is like one pc is the server and the others are diff pc connected with rednet?
ill check it out when home
alexanderht1 #11
Posted 03 January 2013 - 01:48 AM
how do i use this?? could you give me step to step instructions on where to put the file and how to start using it, im gona use it with that MMORPG you made..

edit:

forget it, i found out that you can not run multinet from floppy disks, weird..