Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local liste_client = {}
- local idChannelLogin = 130
- local idChannelAdmin = 131
- local idChannelAdminRep = 13101
- local idChannelMsgRec = 132
- local idChannelMsgEnv = 133
- local keygen = "azerty"
- function attente_client()
- -- attente de connexion/déconnexion des clients
- print("lancement attente_client OK.")
- while true do
- modem.open(idChannelLogin)
- local event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
- if senderChannel == idChannelLogin then
- local msg = textutils.unserialize(text)
- if msg.key == keygen then
- if msg.action == "login" then
- liste_client[msg.id] = msg.nickname
- print("Nouveau client : "..msg.id.." "..liste_client[msg.id])
- elseif msg.action == "leave" then
- table.remove(liste_client, msg.id)
- print("Exit du client : "..msg.id)
- end
- end
- end
- modem.close(idChannelLogin)
- end
- end
- function administration()
- -- envoi régulier d'infos aux clients
- print("lancement admin OK.")
- modem.open(idChannelAdmin)
- while true do
- local event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
- if text == "majliste" then
- local msg = textutils.serialize(liste_client)
- modem.transmit(idChannelAdminRep,idChannelAdmin,msg)
- print("maj liste envoyee")
- end
- end
- modem.close(idChannelAdmin)
- end
- function echange_msg()
- -- reçoit et distribue les messages
- print("lancement echange_msg OK.")
- while true do
- sleep(5)
- end
- end
- modem = peripheral.wrap("back")
- term.clear()
- term.setCursorPos(1,1)
- print("ID du serveur : "..os.getComputerID())
- parallel.waitForAny(attente_client, administration, echange_msg)
- print("Fin du programme")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement