Hello everyone! I have successfully developed a system that allows users to receive “push notifications” onto their mobile phones via email! This has been tested on a iPod touch, and should work fine with Android.
Before I give out the code, I would like to give a special thanks to: FiniteReality [He helped me figure out why the PHP code wasn’t receiving data. THANK YOU SO VERY MUCH!]
Now, all of the following code will be compiled into a model later on. But for now, here is the code:
PHP-Sided code:
<?php
$send_to="youremail@example.com";
$POST = json_decode(file_get_contents("compress.zlib://php://input"), true);
$subject=$POST["Subject"];
$body=$POST["Content"];
mail($send_to,$subject,$body);
echo 'success'
?>
Example GameReporter [Should be used to build your own “logger”]
--Game:Reporter Rewrite 3
--This will be the final rewrite of this
--series. Intended to test service only.
local g=function(s) return game:GetService(s);end;
--LOCAL_VAR
local hs=g'HttpService';
local ns=g'NetworkServer';
local p=g'Players';
local ls=g'LogService';
local app=Enum.HttpContentType.ApplicationJson;
local url="http://server-ip-address-here"; --This can also use a domain name. I perfer IP because no Nameserver.
local ins=table.insert;
--Logging Storage
playerlog={};
outputlog={};
local unqiue_players={};
--System Variables
local place=g'MarketplaceService':GetProductInfo(game.PlaceId~=0 and game.PlaceId or 1818);
local ServerClosing=false;
--Core Functions
local gltime=function()
local now=tick()%86400;
return string.gsub(string.format('%d:%d:%d',math.modf(now/60/60),math.modf(now/60)%60,math.modf(now)%60),'%d+',function(str)
return #str==1 and'0'..str or str;
end);
end;
local Push=function(subject,body)
local data=hs:JSONEncode({['Subject']=subject,['Content']=body});
return hs:PostAsync(url,data,app);
end;
local UploadLog=function()
local st="--PlayerLog Begin--\n";
for i,v in next,playerlog do
st=st.."\n \n"..v;
playerlog[i]=nil;
end;
st=st.."\n \n--End of PlayerLog--\n--OutputLog begin--\n";
for i,v in next,outputlog do
st=st.."\n \n"..v;
outputlog[i]=nil;
end;
st=st.."\n \n--End of OutputLog--\n--End of report--";
return pcall(function() return Push("Report for "..place.Name,st);end);
end;
local Record=function(s,w)
if w=='playerlog' then
ins(playerlog,"["..gltime().."] "..s);
elseif w=='outputlog' then
ins(outputlog,"["..gltime().."] "..s);
end;
end;
--Event Connections
ns.ChildAdded:connect(function(c)
if not c.ClassName:lower():match('replicator') then
pcall(function() c:Destroy() end);
else
Record("A new connection was detected on "..place.Name,'playerlog');
end;
end);
p.PlayerAdded:connect(function(p)
Record(p.Name..p.userId.." has joined "..place.Name.." ["..game.JobId.."]",'playerlog');
p.Chatted:connect(function(msg)
pcall(function()
Record(p.Name..p.userId..": "..msg,"playerlog");
end)
end)
if not unqiue_players[v.userId] then
unqiue_players[v.userId]=true;
end;
end);
p.PlayerRemoving:connect(function(p)
Record(p.Name..p.userId.." has left "..place.Name.." ["..game.JobId.."]",'playerlog');
if not unqiue_players[v.userId] then
unqiue_players[v.userId]=true;
end;
end);
ls.MessageOut:connect(function(message,kind)
local e=Enum.MessageType;
Record("["..tostring(kind==e['MessageOutput'] and "Print" or kind==e['MessageInfo'] and "Info" or kind==e['MessageWarning'] and "Warning" or kind==e['MessageError'] and "Error").."] : "..message,'outputlog');
end)
game.OnClose=function()
ServerClosing=true;
Record("Server is terminating an Instance of "..place.Name.." ["..game.JobId.."]",'outputlog');
Record("Total of Unqiue Visitors this session: "..#unqiue_players,'outputlog');
UploadLog();
return true;
end;
for i,p in next,g'Players':GetPlayers() do
coroutine.wrap(function()
Record(p.Name..p.userId.." has joined "..place.Name.." ["..game.JobId.."]",'playerlog');
p.Chatted:connect(function(msg)
pcall(function()
Record(p.Name..p.userId..": "..msg,"playerlog");
end)
end)
if not unqiue_players[p.userId] then
unqiue_players[p.userId]=true;
end;
end)()
end
while true do
print'Loop initiated.';
for i=240,1,-1 do
if ServerClosing then break end;
print(i.." second"..(i>1 and "s" or "").." remain until upload.");
wait(1);
end;
local suc,res=pcall(function() UploadLog();end);
print(suc,res)
end;
Do whatever you please with the following code. It is YOURS.
I hope this is put into good use, and many users can figure out how to track “important” notifications using this.