@name Computer[By Danus]
@inputs C:wirelink
@outputs
@persist Stage Name:string Log:array
@model models/props_lab/harddrive02.mdl

if(first())
{    
    function void resetM(S,E)
    {
        for(I = S,E)
        {
            C:writeCell(2039,I)
        }
    }
    
    function void logS(S:string,Mess:string,E:entity)
    {
        if(Mess == "!sendmes")
        {
            Log:pushString("[Sent]"+S+"[To Server]")
            C:writeString(Log[Log:count(),string],0,Log:count(),1000)
        }
        elseif(Mess == "!connect")
        {
            Log:pushString("Connected to "+S+"[From Server]")
            C:writeString(Log[Log:count(),string],0,Log:count(),1000)
            Log:pushString("[Sent]Connection[To Server]")
            C:writeString(Log[Log:count(),string],0,Log:count(),1000)
        }
        elseif(Mess == "!sendto")
        {
            local Chat = S:explode(",")
            Log:pushString("[Sending]"+Chat[2,string]+" to ["+Chat[1,string]+"]")
            C:writeString(Log[Log:count(),string],0,Log:count(),1000)
        }
        elseif(Mess == "mes")
        {
            local Chat = S:explode(",")
            if(Chat[2,string]:toNumber() == entity():id())
            {
                Log:pushString("[From Server][ID "+Chat[1,string]+" Sent]"+Chat[3,string])
                C:writeString(Log[Log:count(),string],0,Log:count(),1000)
            }
        }    
        
        if(Log:count() > 14)
        {
            Log:shift()
            for(I = 2,13)
            {
                C:writeString(Log[I,string],0,I,1000)
            }
        }
    }
    
    runOnTick(1)
    runOnChat(1)

    Log:pushString("")
    entity():setAng(ang(0,180,0))
    dsSetScope(0)
    setName("Server Communication[OFFLINE]
    "+entity():id())
    C:writeCell(2041,1)
    C:writeString("Danusian Communication System",0,0,1000)
    C:writeString("=======Server[]========",0,1,1000)
}

if(chatClk(owner()))
{
    local Chat = owner():lastSaid():explode(" ")
    local Text = ""
    
    if(Chat[1,string] == "!connect" & Chat[2,string] == entity():id():toString() & dsGetGroups():count() == 0)
    {
        hideChat(1)
        dsJoinGroup(Chat[3,string])
        Name = Chat[3,string]
        Stage = 1
        setName("Server Communication["+Name+"]
        "+entity():id())
        C:writeString("=======Server["+Name+"]========",1,1,1000)
        logS(Name,Chat[1,string],noentity())
        timer("send",1000)
    }
    elseif(dsGetGroups():count() > 0 & Chat[1,string] == "!sendmes" & Chat[2,string] == entity():id():toString())
    {
        hideChat(1)
        if(Chat:count() > 3)
        {
            for(I = 3, Chat:count())
            {
                if(I < Chat:count())
                {
                    Text += Chat[I,string]+" "
                }
                else
                {
                    Text+= ""+Chat[I,string]
                }
            }
        }
        else
        {
            Text = Chat[3,string]
        }

        
        dsSend("server",Name,Text)
        logS(Text,Chat[1,string],noentity())
    }
    elseif(dsGetGroups():count() > 0 & Chat[1,string] == "!sendto" & Chat[2,string] == entity():id():toString() & Chat[3,string]:toNumber() > 0)
    {
        hideChat(1)
        dsSend("sendto",Name,Chat[3,string]+","+Chat[4,string])
        logS(Chat[3,string]+","+Chat[4,string],Chat[1,string],noentity())
    }
}

if(dsClk())
{
    if(dsGetString() != "reset")
    {   
        logS(dsGetString(),dsClkName(),noentity())
    }
    else
    {
        reset()
    }
}
