Add files via upload

This commit is contained in:
Ryan Ward 2016-12-03 00:43:42 -05:00 committed by GitHub
parent 0e92cb4822
commit c47f1892f8
2 changed files with 14 additions and 3 deletions

View File

@ -21,7 +21,14 @@ function net.chatting:init() -- calling this initilizes the library and binds it
msg=msg msg=msg
} }
self.OnChatRecieved:Fire(struct) -- trigger the chat event 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
end) end)
s.rooms={} s.rooms={}
@ -34,10 +41,11 @@ function net.chatting:init() -- calling this initilizes the library and binds it
net.OnClientCreated:connect(function(c) net.OnClientCreated:connect(function(c)
c.OnDataRecieved:connect(function(self,data) -- when the client recieves data this method is triggered c.OnDataRecieved:connect(function(self,data) -- when the client recieves data this method is triggered
--First Lets make sure we are getting chatting data --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 if user and msg then
--This is the client so our job here is done --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
end) end)
function c:sendChat(user,msg) function c:sendChat(user,msg)

View File

@ -3,4 +3,7 @@ require("Libs/MultiManager") -- allows for multitasking
require("net") -- Loads the networking library require("net") -- Loads the networking library
require("net.chatting") -- loads the networking chatting module require("net.chatting") -- loads the networking chatting module
server=net:newTCPServer(12345) -- starts a server with the port 12345 on local host 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 multi:mainloop() -- starts the mainloop to keep the server going