Compare commits

..

No commits in common. "master" and "Bata" have entirely different histories.
master ... Bata

9 changed files with 103 additions and 4653 deletions

View File

@ -1,6 +1,2 @@
# IntroSoftwareProject # IntroSoftwareProject
All the code All the code
Also a working example of my 3 main libraries (multi, bin, and net) and their usage with love2d.
Feel free to look through the code to get an understanding of how things work together

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

View File

@ -3,7 +3,7 @@ function love.conf(t)
t.version = "0.10.1" -- The LOVE version this game was made for (string) t.version = "0.10.1" -- The LOVE version this game was made for (string)
t.console = true -- Attach a console (boolean, Windows only) t.console = true -- Attach a console (boolean, Windows only)
t.window.title = "Chat Client" -- The window title (string) t.window.title = "game" -- The window title (string)
t.window.icon = nil -- Filepath to an image to use as the window's icon (string) t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
t.window.width = 400 -- The window width (number) t.window.width = 400 -- The window width (number)
t.window.height = 600 -- The window height (number) t.window.height = 600 -- The window height (number)

View File

@ -1,128 +0,0 @@
gui.LoadAll("Interface")
if not client then
-- handle client not being created!
else
client.OnUserLoggedIn:connect(function(self,data)
lMenu.bar.text="Logged In!"
lMenu.anim.Visible=false
end)
client.OnBadLogin:connect(function(self)
lMenu.bar.text="Pass/User incorrect!"
lMenu.anim.Visible=false
end)
client.OnUserAlreadyRegistered:connect(function(self,nick)
lMenu.bar.text="Username Taken!"
lMenu.anim.Visible=false
end)
client.OnUserAlreadyLoggedIn:connect(function(self)
lMenu.bar.text="Already logged in!"
lMenu.anim.Visible=false
end)
client.OnUserRegistered:connect(function(self,nick)
lMenu.bar.text="Register Success!"
lMenu.anim.Visible=false
end)
client.OnNoUserWithName:connect(function(self,nick)
lMenu.bar.text="No User with that name!"
lMenu.anim.Visible=false
end)
client.OnPasswordRequest:connect(function(self)
lMenu.bar.text="Password request sent!"
lMenu.anim.Visible=false
end)
end
--gui.setBG("fire.jpg")
--Login Windows
lMenu=gui:newFrame(0,0,200,100)
lMenu.ClipDescendants=true
lMenu:ApplyGradient{Color.Lighten(Color.Blue,.40),Color.Lighten(Color.Blue,.25),direction="vertical"}
lMenu.bar=lMenu:newTextLabel("","",0,0,0,20,0,0,1)
lMenu.bar:ApplyGradient{Color.Blue,Color.Darken(Color.Blue,.25)}
lMenu.bar.TextColor=Color.Lighten(Color.Red,.25)
lMenu.user=lMenu:newTextBox("username","username",5,25,190,20)
lMenu.pass=lMenu:newTextBox("password","password",5,50,190,20)
lMenu.email=lMenu:newTextBox("email","email",5,100,190,20)
lMenu.nick=lMenu:newTextBox("nick","nick",5,75,190,20)
lMenu.user.TextFormat="left"
lMenu.pass.TextFormat="left"
lMenu.email.TextFormat="left"
lMenu.nick.TextFormat="left"
lMenu.bar.TextFormat="left"
lMenu.bar.Tween=-3
lMenu.user.Tween=-3
lMenu.pass.Tween=-3
lMenu.email.Tween=-3
lMenu.nick.Tween=-3
lMenu.user.ClearOnFocus=true
lMenu.pass.ClearOnFocus=true
lMenu.email.ClearOnFocus=true
lMenu.nick.ClearOnFocus=true
lMenu.user:ApplyGradient{Color.Darken(Color.Blue,.20),Color.Blue,direction="vertical"}
lMenu.pass:ApplyGradient{Color.Darken(Color.Blue,.20),Color.Blue,direction="vertical"}
lMenu.pass.hidden=true
lMenu.email:ApplyGradient{Color.Darken(Color.Blue,.20),Color.Blue,direction="vertical"}
lMenu.nick:ApplyGradient{Color.Darken(Color.Blue,.20),Color.Blue,direction="vertical"}
lMenu.hider=lMenu:newFrame("",1,-29,-2,28,0,1,1)
lMenu.hider.BorderSize=0
lMenu.hider:ApplyGradient{Color.Lighten(Color.Blue,.40),Color.Lighten(Color.Blue,.25),direction="vertical"}
lMenu.Login=lMenu:newTextButton("Login","Login",5,-25,90,20,0,1)
lMenu.Register=lMenu:newTextButton("Register","Register",105,-25,90,20,0,1)
lMenu.Login.Tween=-3
lMenu.Register.Tween=-3
lMenu.Login.Color=Color.Green
lMenu.Register.Color=Color.Red
lMenu.step=multi:newTStep(1,80,1,.01)
lMenu.step:Pause()
lMenu.step.link=lMenu
lMenu.step:OnStep(function(pos,self)
if self.link.height<=150 then
self.link:SetDualDim(nil,nil,nil,self.link.height+1)
lMenu:centerY()
end
print(self.link.height)
end)
lMenu.step2=multi:newTStep(1,80,1,.01)
lMenu.step2:Pause()
lMenu.step2.link=lMenu
lMenu.step2:OnStep(function(pos,self)
if self.link.height>=101 then
self.link:SetDualDim(nil,nil,nil,self.link.height-1)
lMenu:centerY()
end
print(self.link.height)
end)
lMenu.Register:OnReleased(function(b,self)
if self.Parent.Login.text=="Back" then
print(lMenu.pass.ttext)
client:register(lMenu.user.text,lMenu.pass.ttext,lMenu.nick.text,{email=lMenu.email.text})
lMenu.anim.Visible=true
else
self.Parent.Login.text="Back"
self.Parent.Login.Color=Color.saddle_brown
self.Parent.nick.text="nick"
self.Parent.step:Update()
end
end)
lMenu.Login:OnReleased(function(b,self)
if self.text=="Back" then
self.text="Login"
self.Color=Color.Green
self.Parent.step2:Update()
else
print(lMenu.pass.ttext)
client:logIn(lMenu.user.text,lMenu.pass.ttext)
lMenu.anim.Visible=true
end
end)
lMenu:centerX()
lMenu:centerY()
lMenu.anim=lMenu:newAnim("loading",.01, 0, 0, 41, 39)
lMenu.anim:OnAnimEnd(function(self)
self:Reset()
self:Resume()
end)
lMenu.anim:OnUpdate(function(self)
self:centerX()
self:centerY()
end)
lMenu.anim.Visible=false

View File

@ -9,415 +9,105 @@ require("Libs/lovebind") -- binds my libraies to the love2d engine that i am usi
require("GuiManager") -- allows the use of graphics in the program. require("GuiManager") -- allows the use of graphics in the program.
require("net") -- Loads the networking library require("net") -- Loads the networking library
require("net.chatting") require("net.chatting")
require("net.settings") -- loads the networking settings module client=net:newTCPClient("localhost",12345) -- Connects to the server
require("net.identity") -- loads the networking identity module
client=net:newTCPClient("localhost",12345)
if type(client)=="boolean" then error("Please run the server file first!") end if type(client)=="boolean" then error("Please run the server file first!") end
client.OnUserLoggedIn:connect(function(self,data)
anim.Visible=false
login:Destroy()
MY_Name=data.nick
INIT()
end)
client.OnBadLogin:connect(function(self)
header.text="Login/Register (Pass/User incorrect!)"
anim.Visible=false
end)
client.OnUserAlreadyRegistered:connect(function(self,nick)
header.text="Login/Register (Username Taken!)"
anim.Visible=false
end)
client.OnUserRegistered:connect(function(self,nick)
header.text="Login/Register (Register Success!)"
anim.Visible=false
end)
client.OnNoUserWithName:connect(function(self,nick)
header.text="Login/Register (No User with that name!)"
anim.Visible=false
end)
client.OnPasswordRequest:connect(function(self)
header.text="Login/Register (Password request sent!)"
anim.Visible=false
end)
gui.ff.BorderSize=0
login=gui:newFrame("Login",0,0,0,0,0,0,1,1)
login.Color=Color.Black
header=login:newTextLabel("Login/Register",0,10,0,20,0,0,1)
header.TextColor=Color.White
header:setNewFont(20)
header.Visibility=0
username=login:newTextBox("","Username",11,52,-22,35,0,0,1)
t1=username:newTextLabel("Username",0,10,0,30,0,-1,1)
password=login:newTextBox("","Password",11,117,-22,35,0,0,1)
password.hidden=true
t2=password:newTextLabel("Password",0,10,0,30,0,-1,1)
Login=password:newTextButton("Login",0,10,100,30,0,1)
Login.Color=Color.Green
Register=Login:newTextButton("Register",10,0,100,30,1)
Register.Color=Color.Blue
nickname=login:newTextBox("","Nick",11,182,-22,35,0,0,1)
nickname.Visible=false
t3=nickname:newTextLabel("Nickname",0,10,0,30,0,-1,1)
email=login:newTextBox("","Email",11,247,-22,35,0,0,1)
email.Visible=false
t4=email:newTextLabel("Email",0,10,0,30,0,-1,1)
Back=email:newTextButton("Back",0,10,100,30,0,1)
Back.Color=Color.Red
DoRegister=Back:newTextButton("Register",10,0,100,30,1)
DoRegister.Color=Color.Blue
Login:OnReleased(function(b,self)
client:logIn(username.text,password.ttext)
anim.Visible=true
end)
Register:OnReleased(function(b,self)
Login.Visible=false
email.Visible=true
nickname.Visible=true
end)
Back:OnReleased(function(b,self)
Login.Visible=true
nickname.Visible=false
email.Visible=false
end)
DoRegister:OnReleased(function(b,self)
client:register(username.text,password.ttext,nickname.text,{email=email.text})
Login.Visible=true
nickname.Visible=false
email.Visible=false
Register.Visible=false
end)
gui.massMutate({
"setRoundness(10,10,360)",
Tween=1,
XTween=-3,
},Login,Register,Back,DoRegister)
gui.massMutate({
Visibility=0,
TextFormat="left",
TextColor=Color.White,
},t1,t2,t3,t4)
gui.massMutate({
"setRoundness(5,5,360)",
Visibility=1,
TextFormat="left",
Tween=4,
Color=Color.White,
XTween=4,
},username,password,nickname,email)
client.OnChatRecieved(function(user,msg,isself) -- hook to grab chat data client.OnChatRecieved(function(user,msg,isself) -- hook to grab chat data
AG.holder:AddChatBubble(user,msg,isself) Chat:AddChatBubble(user,msg,isself)
end) end)
client.OnPrivateChatRecieved(function(user,msg,USERID) -- hook to grab chat data --gui.enableAutoWindowScaling(true) -- allows mobile support. Not needed for PC use
print("Matching: ",app[USERID],USERID) nameframe=gui:newFrame("",0,0,200,100)
local lastCFrame=CFrame nameframe.Color=Color.Lighten(Color.Brown,.15)
if app[USERID] then nameframe:setRoundness(15,15,360)
CFrame=app[USERID] nameframe:centerX()
--local c=AC.holder:getChildren() nameframe:centerY()
--for i=1,#c do namer=nameframe:newTextBox("Please enter a name to use!",0,0,180,30)
-- c[i].Visible=false namer:centerX()
--end namer:centerY()
--CFrame.Visible=true namer.Color=Color.tan
--local c=Chatting:getChildren() namer.ClearOnFocus=true
--for i=1,#c do namer:setRoundness(5,5,360)
-- c[i].Color=Color.Yellow namer:OnEnter(function(self,txt)
--end MY_Name=txt:gsub("%s","_")
--CFrame.button.Color=Color.Green InitEngine()
end nameframe:Destroy()
AC:PopulateChat(user,msg) gui.ff:Destroy()
CFrame=lastCFrame -- reset cframe after stuff has been done end)
gui.ff.C1=45
gui.ff.C2=193
gui.ff.C3=92
gui.ff.C1m=-1
gui.ff.C2m=1
gui.ff.C3m=-1
gui.ff.Color=Color.Blue
func=multi:newFunction(function(l,self) -- not needed just adds color change when chosing a name
l:hold(.05)
self.C1=self.C1+(({1,2,3})[math.random(1,3)]*self.C1m)
self.C2=self.C2+(({1,2,3})[math.random(1,3)]*self.C2m)
self.C3=self.C3+(({1,2,3})[math.random(1,3)]*self.C3m)
if self.C1>255 then self.C1=254 self.C1m=-1 end
if self.C2>255 then self.C2=254 self.C2m=-1 end
if self.C3>255 then self.C3=254 self.C3m=-1 end
if self.C1<0 then self.C1=1 self.C1m=1 end
if self.C2<0 then self.C2=1 self.C2m=1 end
if self.C3<0 then self.C3=1 self.C3m=1 end
self.Color=Color.new(self.C1,self.C2,self.C3)
end) end)
function love.wheelmoved(x, y) -- handle scrolling function love.wheelmoved(x, y) -- handle scrolling
if CFrame==nil then return end if mainapp then else return end
local c=CFrame.holder:getChildren()
if y > 0 then if y > 0 then
CFrame.holder.offset.pos.y=CFrame.holder.offset.pos.y+10 Chat.bubbles:SetDualDim(nil,Chat.bubbles.y+10)
elseif y < 0 then elseif y < 0 then
CFrame.holder.offset.pos.y=CFrame.holder.offset.pos.y-10 Chat.bubbles:SetDualDim(nil,Chat.bubbles.y-50)
end end
if CFrame.holder.offset.pos.y>0 then if Chat.bubbles.offset.pos.y>0 then
CFrame.holder.offset.pos.y=0 Chat.bubbles.offset.pos.y=0
elseif CFrame.holder.offset.pos.y<-(#c*35) then
CFrame.holder.offset.pos.y=-(#c*35)
end end
print(Chat.bubbles.offset.pos.y)
end end
function INIT() gui.ff:OnUpdate(func)
love.mouse.setCursor(love.mouse.getSystemCursor("arrow")) function InitEngine()
app=gui:newImageLabel("bg.jpg",0,0,0,0,0,0,1,1) mainapp=gui:newFrame("",0,0,0,0,0,0,1,1) -- creates a frame that takes up the enitre window
app.PrivateChats={} mainapp.Color=Color.Lighten(Color.Brown,.25)
app.PrivateChatsRef={} mainapp.BorderSize=0
app.ServerUpdate=multi:newAlarm(30)-- every 30 seconds mainapp.header=mainapp:newTextLabel("Now chatting as: "..MY_Name,1,-10,-2,30,0,0,1) -- creates the header for the app
app.ServerUpdate:OnRing(function(alarm) mainapp.header:setRoundness(15,15,360)
client:getUserList() mainapp.header.Tween=7 -- moves the text up by a factor of 3 pixels
alarm:Reset() mainapp.header.Color=Color.Lighten(Color.Blue,.25) -- Sets the Color of the header object to light blue
end) mainapp.chatFrame=mainapp:newFrame("",0,21,0,-20,0,0,1,1) -- creates the chat frame where users can see the text that is sent
header=app:newFrame("Header",0,0,0,60,0,0,1) mainapp.chatFrame.Color=Color.Lighten(Color.Brown,.25) -- Color stuff
header:ApplyGradient{Color.Black,Color.Lighten(Color.Black,.10)} mainapp.chatFrame.ClipDescendants=true
header.BorderSize=0 mainapp.chatFrame.bubbles=mainapp.chatFrame:newFrame("",0,0,0,0,0,0,1)
loggedInAs=header:newTextLabel("Logged in as: "..MY_Name,-250,0,250,20,1) mainapp.chatFrame.bubbles.Visibility=0
loggedInAs.TextColor=Color.White Chat=mainapp.chatFrame
loggedInAs.Tween=2 Chat.lastBubbleHeight=0
loggedInAs.Visibility=0 function Chat:AddChatBubble(user,txt,isself)
Options=header:newFrame("OptionHolder",0,0,0,30,0,1,1)
Options.Color=Color.Lighten(Color.Black,.10)
Options.BorderSize=0
Online=Options:newTextLabel("Online",0,0,0,0,2/3,0,1/3,1)
CChat=Options:newTextLabel("Private Chats",0,0,0,0,0,0,1/3,1)
Global=Options:newTextLabel("Global Chat",0,0,0,0,1/3,0,1/3,1)
app["Online"]=app:newFrame(0,90,0,-150,0,0,1,1)
AO=app["Online"]
--Online.Visible=false
AO.holder=AO:newFrame("Holder",0,0,0,0,0,0,1,1)
AO.holder.Visibility=0
app["Private Chats"]=app:newFrame(0,90,0,-90,0,0,1,1)
AC=app["Private Chats"]
AC.holder=AC:newFrame("Holder",0,0,0,0,.4,0,.6,1)
AC.holder.Visibility=0
AC.CurrentUSERID=""
AC.CurrentNick=""
Chatting=AC:newFrame("Chatting",0, 0, 0, 0, 0 ,0 ,.4 ,1)
Chatting.Color=Color.Lighten(Color.Black,.10)
app["Global Chat"]=app:newFrame(0,90,0,-150,0,0,1,1)
AG=app["Global Chat"]
AG.holder=AG:newFrame("Holder",0,0,0,0,0,0,1,1)
AG.holder.Visibility=0
AC.lastBubbleHeight=0
AG.holder.lastBubbleHeight=0
function AC:sendChat(msg)
--
end
function AG.holder:AddChatBubble(user,txt,USERID)
local msg=user..": "..txt local msg=user..": "..txt
local width, wrappedtext = _defaultfont:getWrap(msg, math.floor(app.width/2)-10) local bubble=self.bubbles:newTextLabel(msg,0,self.lastBubbleHeight+5,math.floor(mainapp.width/2),(math.ceil(#msg/24)*12)+5)
local height = _defaultfont:getHeight() bubble.TextFormat="left"
local bubble=self:newTextLabel("",0,self.lastBubbleHeight+5,math.floor(app.width/2),#wrappedtext*height+6) bubble.XTween=2
bubble.TFrame=bubble:newTextLabel(msg,8,0,-16,0,0,0,1,1) bubble.Tween=-4
bubble.TFrame.Visibility=0
bubble.TFrame.TextFormat="left"
bubble.TFrame.Tween=-4
bubble.TFrame.TextColor=Color.White
bubble.Color=Color.White
bubble:setRoundness(5,5,360) bubble:setRoundness(5,5,360)
bubble.Visibility=.5
bubble.Color=Color.Black
if user==MY_Name then
bubble.TFrame.text=bubble.TFrame.text:gsub("("..user.."):","You:")
bubble:anchorRight(1)
end
self.lastBubbleHeight=self.lastBubbleHeight+#wrappedtext*height+11
if self.lastBubbleHeight>self.height-20 then
self.offset.pos.y=-(self.lastBubbleHeight-(self.height-20))
end
end
function AG:sendChat(msg)
client:sendChat(MY_Name,msg)
end
function AC:PopulateChat(user,msg,isself)
if CFrame.IsPChat then
local width, wrappedtext = _defaultfont:getWrap(msg, math.floor((CFrame.width)/2))
local height = _defaultfont:getHeight()
local bubble;
if #wrappedtext>1 then
bubble=CFrame:newTextLabel("",0,CFrame.lastBubbleHeight+5,0,(#wrappedtext+1)*height+6,0,0,.5)
else
bubble=CFrame:newTextLabel("",0,CFrame.lastBubbleHeight+5,0,(#wrappedtext)*height+6,0,0,.5)
end
bubble.TFrame=bubble:newTextLabel(msg,8,0,-16,0,0,0,1,1)
bubble.TFrame.Visibility=0
bubble.TFrame.TextFormat="left"
bubble.TFrame.Tween=-4
bubble.TFrame.TextColor=Color.White
bubble.Color=Color.White
bubble:setRoundness(5,5,360)
bubble.Visibility=.5
bubble.Color=Color.Black
if isself then if isself then
bubble.TFrame.text="You: "..msg
bubble:anchorRight(1) bubble:anchorRight(1)
else
bubble.TFrame.text=CFrame.Nick..": "..msg
end end
print(#wrappedtext) self.lastBubbleHeight=self.lastBubbleHeight+(math.ceil(#msg/24)*12)+13
if #wrappedtext>1 then if self.lastBubbleHeight>mainapp.height-60 then
CFrame.lastBubbleHeight=CFrame.lastBubbleHeight+(#wrappedtext+1)*height+11 self.bubbles.offset.pos.y=-(self.lastBubbleHeight-(mainapp.height-60))
else
CFrame.lastBubbleHeight=CFrame.lastBubbleHeight+(#wrappedtext)*height+11
end
if CFrame.lastBubbleHeight>CFrame.height-20 then
CFrame.offset.pos.y=-(CFrame.lastBubbleHeight-(self.height-20))
end end
end end
end mainapp.textbox=mainapp:newTextBox("",5,-35,-10,30,0,1,1) -- creates a textbox that allows the user to be able to send messages
CFrame=nil mainapp.textbox.TextFormat="left" -- sets the format to left hand side of screen
client.OnUserList(function(list) mainapp.textbox.Color=Color.tan
if input.Visible then mainapp.textbox:setRoundness(5,5,360)
c=0 mainapp.textbox:OnEnter(function(self,txt) -- handles the send event
local collections={} client:sendChat(MY_Name,txt) -- sends the data to the server
local childs=AC.holder:getChildren()
for i=1,#childs do
collections[childs[i].Name]=childs[i]
end
for i,v in pairs(list) do
collections[v]=nil
if i~=MY_Name and not(AC.holder.Children[v]) then
local temp=Chatting:newTextLabel(i,0,20*(c+#Chatting:getChildren()),0,20,0,0,1)
c=c+1
temp:setRoundness(7,7,360)
temp.Color=Color.Yellow
temp.Tween=-4
temp.USERID=v
temp.link=AC.holder:newFrame(v,0,0,0,0,0,0,1,1)
temp.link.Visibility=0
app[v]=temp.link
temp.link.Visible=false
temp.link.USERID=v
temp.link.Nick=i
temp.link.holder=temp.link
temp.link.button=temp
function temp.link:sendChat(txt)
AC:PopulateChat("",txt,true)
client:sendChatTo(MY_Name,self.USERID,txt)
end
temp.link.IsPChat=true
temp.link.lastBubbleHeight=0
temp:OnReleased(function(b,self)
CFrame=self.link
local c=Chatting:getChildren()
for i=1,#c do
c[i].Color=Color.Yellow
end
temp.Color=Color.Green
local c=AC.holder:getChildren()
for i=1,#c do
c[i].Visible=false
end
self.link.Visible=true
end)
end
end
for i,v in pairs(collections) do
collections[i].button:Destroy()
collections[i]:Destroy()
AC.holder.Children[i]=nil
end
local c=Chatting:getChildren()
for i=1,#c do
c[i]:SetDualDim(0,20*(i-1),0,20,0,0,1)
end
else
anim.Visible=false
local c=AO.holder:getChildren()
for i=1,#c do
c[i]:Destroy()
end
c=0
for i,v in pairs(list) do
if i~=MY_Name then
local temp=AO.holder:newTextLabel(i,0,(c)*35,0,30,0,0,.5)
c=c+1
temp.USERID=v
temp:setRoundness(5,5,360)
temp.Color=Color.dark_gray
temp.Tween=2
temp:OnReleased(function(b,self)
table.insert(app.PrivateChats,{i,self.USERID})
end)
end
end
end
end)
function AO:Act()
CFrame=self
anim.Visible=true
input.Visible=false
client:getUserList()
end
function AC:Act()
input.Visible=true
CFrame=self
input:setDualDim(0,-60,0,60,.4,1,.6)
input:setRoundness(nil,nil,nil)
client:getUserList()
end
function AG:Act()
input.Visible=true
CFrame=self
input:setDualDim(0,-60,0,60,0,1,1)
input:setRoundness(10,10,360)
end
function app:hideOptions()
gui.massMutate({
Visible=false,
},app["Online"],app["Private Chats"],app["Global Chat"])
end
gui.massMutate({
Visibility=0,
ClipDescendants=true,
Visible=false,
},app["Online"],app["Private Chats"],app["Global Chat"])
gui.massMutate({
Tween=2,
Visibility=0,
TextColor=Color.Darken(Color.White,.3),
"setNewFont(18)",
[[OnEnter(function(self)
self.TextColor=Color.White
end)]],
[[OnExit(function(self)
self.TextColor=Color.Darken(Color.White,.3)
end)]],
[[OnReleased(function(b,self)
app:hideOptions()
app[self.text].Visible=true
app[self.text]:Act()
end)]],
},Online,CChat,Global)
textDisp=header:newTextLabel("Chats",10,15,100,30)
textDisp.TextFormat="left"
textDisp:setNewFont(28)
textDisp.TextColor=Color.White
textDisp.Visibility=0
input=app:newFrame("InputHolder",0,-60,0,60,0,1,1)
input:anchorRight(1)
input.Visibility=1
input.BorderSize=0
input:setRoundness(10,10,360)
input:ApplyGradient{Color.Black,Color.Lighten(Color.Black,.10)}
input.Visible=false
textbox=input:newTextBox("",11,14,-22,-25,0,0,1,1)
textbox:setRoundness(5,5,360)
textbox.Visibility=1
textbox.TextFormat="left"
textbox.Tween=4
textbox.Color=Color.White
textbox.XTween=4
textbox.ClipDescendants=true
input:OnUpdate(function(self)
local width, wrappedtext = _defaultfont:getWrap(textbox.text, textbox.width)
local height = _defaultfont:getHeight()
if #wrappedtext==0 then
input:SetDualDim(0,-60,0,60,0,1,1)
else
input:SetDualDim(0,-60-((#wrappedtext-1)*(height)),0,60+((height)*(#wrappedtext-1)),0,1,1)
end
end)
textbox:OnEnter(function(self,txt)
CFrame:sendChat(txt)
self.text="" self.text=""
self.ttext="" self.Color=Color.tan
end) end)
AG.Visible=true mainapp.textbox:OnFocus(function(self)
AG:Act() self.Color=Color.Lighten(Color.tan,.25)
end)
mainapp.textbox.ClearOnFocus=true
mainapp.textbox.XTween=2
mainapp.textbox.Tween=2 -- positions the text in the text box
end end
--must be last object created!
anim=gui:newAnim("loading",.01, 0, 0, 41, 39)
anim.Visible=false
anim:OnAnimEnd(function(self)
self:Reset()
self:Resume()
end)
anim:OnUpdate(function(self)
self:centerX()
self:centerY()
end)
--~ bubble=gui:newFrame("Test",100,100,100,100)

View File

@ -1,5 +1,4 @@
require("net") require("net")
require("net.identity")
--General Stuff --General Stuff
--[[ What this module does! --[[ What this module does!
Adds Adds
@ -9,78 +8,25 @@ client:OnChatRecieved(function(user,msg) end)
client:sendChat(user,msg) client:sendChat(user,msg)
]] ]]
net:registerModule("chatting",{2,1,0}) net:registerModule("chatting",{2,1,0})
net.chatting.users={}
function net.chatting:getUserIdFromIP(ip)
return net.chatting.users[ip]
end
function net.chatting:init() -- calling this initilizes the library and binds it to the servers and clients created function net.chatting:init() -- calling this initilizes the library and binds it to the servers and clients created
--Server Stuff --Server Stuff
net.OnServerCreated:connect(function(s) net.OnServerCreated:connect(function(s)
print("The Chatting Module has been loaded onto the server!") print("The Chatting Module has been loaded onto the server!")
s.OnUserLoggedIn(function(user,cid,ip,port,dTable)
dTable=loadstring("return "..dTable)()
local USERID=bin.new(user):getHash(32)
print(USERID)
net.chatting.users[USERID]={dTable.nick,cid,ip,port,dTable} -- add users that log in to the userlist
net.chatting.users[ip]=USERID -- add users that log in to the userlist
local users={}
for i,v in pairs(net.chatting.users) do
if type(i)~="userdata" then
table.insert(users,i.."|"..net.chatting.users[i][1])
end
end
table.insert(users,"")
for i,v in pairs(s.ips) do
s:send(v,"!chatting! $Users|NIL|NIL '"..table.concat(users,",").."'")
end
end)
s.OnUserLoggerOut(function(self,user)
local USERID=bin.new(user):getHash(32)
local ip=net.chatting.users[USERID]
print(USERID)
net.chatting.users[USERID]=nil
net.chatting.users[ip]=nil
end)
s.OnDataRecieved:connect(function(self,data,cid,ip,port) -- when the server recieves data this method is triggered s.OnDataRecieved:connect(function(self,data,cid,ip,port) -- when the server 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 user,msg = data:match("!chatting! (%S-) '(.+)'")
if user and msg then if user and msg then
if user:sub(1,1)=="$" then
local cmd,arg=user:match("$(.+)|(.+)")
print("Using extended chatting protocal!")
if cmd=="DM" then
local struct={ -- pack the info up as a table so the server can do filtering and whatnot to the chat local struct={ -- pack the info up as a table so the server can do filtering and whatnot to the chat
user=user, user=user,
msg=msg msg=msg
} }
self.OnChatRecieved:Fire(struct,"PRIVATE") self.OnChatRecieved:Fire(struct) -- trigger the chat event
print("USERID",arg)
self:send(net.chatting.users[arg][3],"!chatting! $DM|"..net.chatting.users[arg][1].."|"..net.chatting:getUserIdFromIP(ip).." '"..msg.."'",net.chatting.users[arg][4])
elseif cmd=="getUsers" then
local users={}
for i,v in pairs(net.chatting.users) do
if type(i)~="userdata" then
table.insert(users,i.."|"..net.chatting.users[i][1])
end
end
table.insert(users,"")
self:send(ip,"!chatting! $Users|NIL|NIL '"..table.concat(users,",").."'",port)
elseif cmd=="getPrivateChat" then -- will do later!
--send: "!sft! *...*"
end
else
local struct={ -- pack the info up as a table so the server can do filtering and whatnot to the chat
user=user,
msg=msg
}
self.OnChatRecieved:Fire(struct,"GROUP") -- trigger the chat event
local USERID=net.chatting:getUserIdFromIP(ip)
for i,v in pairs(self.ips) do for i,v in pairs(self.ips) do
if ip==v then if ip==v then
self:send(v,"!chatting! 1|"..struct.user.."|"..USERID.." '"..struct.msg.."'") print("Self: "..struct.user)
self:send(v,"!chatting! 1 "..struct.user.." '"..struct.msg.."'")
else else
self:send(v,"!chatting! 0|"..struct.user.."|"..USERID.." '"..struct.msg.."'") self:send(v,"!chatting! 0 "..struct.user.." '"..struct.msg.."'")
end
end end
end end
end end
@ -95,39 +41,16 @@ 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 isself,user,USERID,msg = data:match("!chatting! (%S-)|(%S-)|(%S-) '(.+)'") local isself, user,msg = data:match("!chatting! (%d) (%S-) '(.+)'")
if not isself then return end if user and msg then
if tonumber(isself) 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,({["1"]=true, ["0"]=false})[isself],USERID) -- trigger the chat event print(isself)
elseif isself:sub(1,1)=="$" then self.OnChatRecieved:Fire(user,msg,({["1"]=true, ["0"]=false})[isself]) -- trigger the chat event
local cmd=isself:match("$(.+)")
if cmd=="DM" then
print("DM: ",user,msg,USERID)
c.OnPrivateChatRecieved:Fire(user,msg,USERID)
elseif cmd=="Users" then
local tab={}
for ID,nick in msg:gmatch("(%S-)|(%S-),") do
tab[nick]=ID
end
c.OnUserList:Fire(tab)
end
end end
end) end)
function c:sendChat(user,msg) function c:sendChat(user,msg)
self:send("!chatting! "..user.." '"..msg.."'") self:send("!chatting! "..user.." '"..msg.."'")
end end
function c:sendChatTo(user,touser,msg)
self:send("!chatting! $DM|"..touser.." '"..msg.."'")
end
function c:getUserList()
self:send("!chatting! $getUsers|NIL 'NIL'")
end
function c:getChatFrom(userID)
self:send("!chatting! getPrivateChat|NIL '"..userID.."'") -- add if time permits
end
c.OnPrivateChatRecieved=multi:newConnection()
c.OnUserList=multi:newConnection()
c.OnChatRecieved=multi:newConnection() -- create a chat event c.OnChatRecieved=multi:newConnection() -- create a chat event
end) end)
end end

View File

@ -10,8 +10,6 @@ function net.hash(text,n)
n=n or 16 n=n or 16
return bin.new(text.."jgmhktyf"):getHash(n) return bin.new(text.."jgmhktyf"):getHash(n)
end end
net.identity.UIDS={}
net.identity.UIDS.ids={}
function net.identity:init() -- calling this initilizes the library and binds it to the servers and clients created function net.identity:init() -- calling this initilizes the library and binds it to the servers and clients created
--Server Stuff --Server Stuff
net.OnServerCreated:connect(function(s) net.OnServerCreated:connect(function(s)
@ -41,7 +39,6 @@ function net.identity:init() -- calling this initilizes the library and binds it
self.userFolder=loc self.userFolder=loc
end end
function s:loginUserOut(user) function s:loginUserOut(user)
net.identity.UIDS.ids[user.UID]=nil
self.loggedIn[user]=nil self.loggedIn[user]=nil
end end
function s:loginUserIn(user,cid) function s:loginUserIn(user,cid)
@ -50,7 +47,6 @@ function net.identity:init() -- calling this initilizes the library and binds it
table.merge(self.loggedIn[user],dTable or {}) table.merge(self.loggedIn[user],dTable or {})
self.loggedIn[user].cid=cid self.loggedIn[user].cid=cid
self.loggedIn[user].nick=nick self.loggedIn[user].nick=nick
self.loggedIn[user].UID=net.resolveID(net.identity.UIDS)
return self:getUserDataHandle(user) return self:getUserDataHandle(user)
end end
function s:getUserDataHandle(user) function s:getUserDataHandle(user)
@ -104,7 +100,7 @@ function net.identity:init() -- calling this initilizes the library and binds it
end end
local handle=self:loginUserIn(user,cid) -- binds the cid to username local handle=self:loginUserIn(user,cid) -- binds the cid to username
self:send(ip,"!identity! LOGINGOOD <-|"..bin.ToStr(handle).."|->",port) self:send(ip,"!identity! LOGINGOOD <-|"..bin.ToStr(handle).."|->",port)
self.OnUserLoggedIn:Fire(user,cid,ip,port,bin.ToStr(handle)) self.OnUserLoggedIn:Fire(user,cid,ip,port)
return return
else else
self:send(ip,"!identity! LOGINBAD <-|nil|->",port) self:send(ip,"!identity! LOGINBAD <-|nil|->",port)