Advertisement
meuced

Tchat client v0.1

Oct 19th, 2013
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. local liste_client = {} -- ici, chaque élément sera un couple d'infos : ID client et pseudo
  2.  
  3. local idChannelLogin = 130
  4. local idChannelAdmin = 131
  5. local idChannelAdminRep = 13101
  6. local idChannelMsgRec = 132
  7. local idChannelMsgEnv = 133
  8.  
  9. local keygen = "azerty"
  10.  
  11. function decoration()
  12.     local x, y = 0, 0
  13.     term.clear()
  14.     for x=1,51 do
  15.         paintutils.drawPixel(x,1,colors.red)
  16.         paintutils.drawPixel(x,16,colors.red)
  17.         paintutils.drawPixel(x,19,colors.red)
  18.     end
  19.     for y=2,18 do
  20.         paintutils.drawPixel(1,y,colors.red)
  21.         paintutils.drawPixel(51,y,colors.red)
  22.     end
  23.     for y=2,15 do
  24.         paintutils.drawPixel(11,y,colors.red)
  25.     end
  26.     term.setTextColor(colors.yellow)
  27.     term.setBackgroundColor(colors.red)
  28.     term.setCursorPos(18,1)
  29.     term.write("Tchat by meuced")
  30.     term.setBackgroundColor(colors.black)  
  31.     term.setCursorPos(2,2)
  32.     term.write("Presents:")
  33.     term.setCursorPos(2,17)
  34.     term.write("Votre texte :")
  35.     term.setCursorPos(2,18)
  36.     term.setTextColor(colors.white)
  37.     term.write(">")
  38.     term.setCursorBlink(true)
  39. end
  40.  
  41. function majListeEcran()
  42.    
  43.     local x, y = 0,0
  44.     term.setBackgroundColor(colors.black)
  45.     term.setTextColor(colors.white)
  46.     for x = 2, 10 do
  47.         for y = 3, 15 do
  48.             term.setCursorPos(x,y)
  49.             term.write(" ")
  50.         end
  51.     end
  52.    
  53.     x, y = 2, 3
  54.    
  55.     for key,value in pairs( liste_client ) do
  56.         term.setCursorPos(x,y)
  57.         term.write(liste_client[key])
  58.         y = y+1
  59.     end
  60.    
  61.     term.setCursorPos(3,18)
  62.     term.setCursorBlink(true)
  63.    
  64. end
  65.  
  66. function login()
  67.     term.setTextColor(colors.white)
  68.     print("Se connecter au serveur : ")
  69.     idsrv = tonumber(read())
  70.  
  71.     print("Votre pseudo : ")
  72.     local nickname = read()
  73.     local tableau = {key=keygen , id=os.getComputerID() , nickname=nickname, action="login"}
  74.     local msg = textutils.serialize(tableau)
  75.  
  76.     modem.transmit(idChannelLogin,idChannelLogin,msg)
  77. end
  78.  
  79. function logout()
  80.     local tableau = {key=keygen , id=os.getComputerID() , action="logout"}
  81.     local msg = textutils.serialize(tableau)
  82.  
  83.     modem.transmit(idChannelLogin,idChannelLogin,msg)
  84. end
  85.  
  86. function envoiMsg()
  87.     -- a faire
  88.     -- fonction qui envoie notre texte au serveur
  89. end
  90.  
  91. function echangesAdmEnvoi(envquoi)
  92.     -- a faire
  93.     -- echanges avec le serveur :
  94.     --  maj liste presents, etc...
  95.  
  96.     modem.transmit(idChannelAdmin,idChannelAdminRep,envquoi)
  97.    
  98. end
  99.  
  100. --========================================--
  101. --========================================--
  102.  
  103. function echangesAdmReception()
  104.     -- reception d'infos
  105.     while true do
  106.         modem.open(idChannelAdminRep)
  107.         local event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
  108.         liste_client = textutils.unserialize(text)
  109.         majListeEcran()
  110.         --sleep(5)
  111.     end
  112. end
  113.  
  114. function receptionMsg()
  115.     -- a faire
  116.     -- fonction qui recoit du serveur les textes
  117.     --   des autres utilisateurs et gère le scroll
  118.     while true do
  119.         sleep(5)
  120.     end
  121. end
  122.  
  123. function client()
  124.     -- fonction qui gère la tape des messages
  125.     sleep(1)
  126.     echangesAdmEnvoi("majliste")
  127.     while true do
  128.         sleep(5)
  129.     end
  130. end
  131.  
  132. --========================================--
  133. --========================================--
  134.  
  135. term.clear()
  136. term.setCursorPos(1,1)
  137. modem = peripheral.wrap("back")
  138.  
  139. login()
  140.  
  141. decoration()
  142.  
  143.  
  144. parallel.waitForAny(echangesAdmReception, receptionMsg, client)
  145.  
  146. print("fin du programme")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement