wiremod-svn-archive/wire/lua/autorun/server/radiolib.lua
BlackPhoenix 5aeff6716b [ADDED] I got angry so I made new radiolib. It should fix all of known radio bugs.
[FIXED] GPU now does not have the eww white border around it
[ADDED] Keyboard now has input to kick out whoever is using it at the moment
[ADDED] Keyboard now outputs entity of player who currently uses keyboard
2009-01-17 21:30:07 +00:00

161 lines
4.1 KiB
Lua

//First there was phenes
//Then there was High6
//Then Black Phoenix came and rewrote everything, what a bastard
local Radio_Entities = {}
function Radio_Register(ent)
table.insert(Radio_Entities, ent)
end
/*
function Radio_Update() //FIXME
for ks,vs in ipairs(Radio_Entities) do
if (not IsEntity(vs.Entity)) then //Invalid radio
table.remove(Radio_Entities, ks)
else
if (vs.Transmitting == true) then //Radio has something to transmit
for kr,vr in ipairs(Radio_Entities) do
if (not IsEntity(vr.Entity)) then
table.remove(Radio_Entities, vr)
elseif (ks ~= kr) then
vs.TransmitTo(vr)
end
end
end
end
end
end
hook.Add("Think", "RadioLib_Think", Radio_Update)*/
function Radio_Unregister(ent)
for k,v in ipairs(Radio_Entities) do
if (v == ent) then
table.remove(Radio_Entities, k)
elseif (IsEntity(v.Entity)) then
//Zero out all channels that this radio used
for i=0,31 do
if (v.RecievedData[i].Owner == ent) then
v.RecievedData[i].Owner = nil
v.RecievedData[i].Data = 0
v:NotifyDataRecieved(i)
end
end
v:ShowOutput()
end
end
end
function Radio_SendData(ent, subch, data)
ent.SentData[subch] = data
for k,v in ipairs(Radio_Entities) do
if (not IsEntity(v.Entity)) then //Invalid radio
Radio_Unregister(v)
elseif (ent:EntIndex() != v.Entity:EntIndex()) then //Not sender
if ((ent.Secure) && (v.Secure)) then
if ((ent.pl:SteamID() == v.pl:SteamID()) && (ent.Channel == v.Channel)) then
v.RecievedData[subch].Owner = ent
v.RecievedData[subch].Data = data
v:NotifyDataRecieved(subch)
end
else
if (ent.Channel == v.Channel) then
v.RecievedData[subch].Owner = ent
v.RecievedData[subch].Data = data
v:NotifyDataRecieved(subch)
end
end
v:ShowOutput()
end
end
end
function Radio_RecieveData(ent)
for i=0,31 do
ent.RecievedData[i].Owner = nil
ent.RecievedData[i].Data = 0
ent:NotifyDataRecieved(i)
end
for k,v in ipairs(Radio_Entities) do
if (not IsEntity(v.Entity)) then //Invalid radio
Radio_Unregister(v)
elseif (ent:EntIndex() != v.Entity:EntIndex()) then //Not sender
if ((ent.Secure) && (v.Secure)) then
if ((ent.pl:SteamID() == v.pl:SteamID()) && (ent.Channel == v.Channel)) then
for i=0,31 do
ent.RecievedData[i].Owner = v
ent.RecievedData[i].Data = v.SentData[i]
ent:NotifyDataRecieved(i)
end
end
else
if (ent.Channel == v.Channel) then
for i=0,31 do
ent.RecievedData[i].Owner = v
ent.RecievedData[i].Data = v.SentData[i]
ent:NotifyDataRecieved(i)
end
end
end
end
end
ent:ShowOutput()
end
function Radio_ChangeChannel(ent)
//Request all other radios send data to this radio
Radio_RecieveData(ent)
for k,v in ipairs(Radio_Entities) do
if (not IsEntity(v.Entity)) then //Invalid radio
Radio_Unregister(v)
elseif (ent:EntIndex() != v.Entity:EntIndex()) then //Not sender
//1. Kill all transmissions for this radio
//for i=0,31 do
// if (v.RecievedData[i].Owner == ent) then
// v.RecievedData[i].Owner = nil
// v.RecievedData[i].Data = 0
// v:NotifyDataRecieved(i)
// end
//end
Radio_RecieveData(v)
//2. Retransmit under new channel
if ((ent.Secure) && (v.Secure)) then
if ((ent.pl:SteamID() == v.pl:SteamID()) && (ent.Channel == v.Channel)) then
for i=0,31 do
if (ent.SentData[i] ~= 0) then //dont send zeroes
v.RecievedData[i].Owner = ent
v.RecievedData[i].Data = ent.SentData[i]
v:NotifyDataRecieved(i)
end
end
end
else
if (ent.Channel == v.Channel) then
for i=0,31 do
if (ent.SentData[i] ~= 0) then //dont send zeroes
v.RecievedData[i].Owner = ent
v.RecievedData[i].Data = ent.SentData[i]
v:NotifyDataRecieved(i)
end
end
end
end
v:ShowOutput()
end
end
end
local radio_twowaycounter = 0
function Radio_GetTwoWayID()
radio_twowaycounter = radio_twowaycounter + 1
return radio_twowaycounter
end
-- phenex: End radio mod.
//Modified by High6 (To support 4 values)
//Rebuilt by high6 to allow defined amount of values/secure lines