diff --git a/net/chatting.lua b/net/chatting.lua index 09393df..74f58f3 100644 --- a/net/chatting.lua +++ b/net/chatting.lua @@ -21,7 +21,14 @@ function net.chatting:init() -- calling this initilizes the library and binds it msg=msg } self.OnChatRecieved:Fire(struct) -- trigger the chat event - self:sendAll("!chatting! "..struct.user.." '"..struct.msg.."'") + for i,v in pairs(self.ips) do + if ip==v then + print("Self: "..struct.user) + self:send(v,"!chatting! 1 "..struct.user.." '"..struct.msg.."'") + else + self:send(v,"!chatting! 0 "..struct.user.." '"..struct.msg.."'") + end + end end end) s.rooms={} @@ -34,10 +41,11 @@ function net.chatting:init() -- calling this initilizes the library and binds it net.OnClientCreated:connect(function(c) c.OnDataRecieved:connect(function(self,data) -- when the client recieves data this method is triggered --First Lets make sure we are getting chatting data - local user,msg = data:match("!chatting! (%S-) '(.+)'") + local isself, user,msg = data:match("!chatting! (%d) (%S-) '(.+)'") if user and msg then --This is the client so our job here is done - self.OnChatRecieved:Fire(user,msg) -- trigger the chat event + print(isself) + self.OnChatRecieved:Fire(user,msg,({["1"]=true, ["0"]=false})[isself]) -- trigger the chat event end end) function c:sendChat(user,msg) diff --git a/server.lua b/server.lua index d5ff376..9ba19e2 100644 --- a/server.lua +++ b/server.lua @@ -3,4 +3,7 @@ require("Libs/MultiManager") -- allows for multitasking require("net") -- Loads the networking library require("net.chatting") -- loads the networking chatting module server=net:newTCPServer(12345) -- starts a server with the port 12345 on local host +server.OnChatRecieved(function(struct) -- where we handle users and messages + print(struct.user..": "..struct.msg) +end) multi:mainloop() -- starts the mainloop to keep the server going