[hitsquad] Receive notifications on your Mobile Device from ROBLOX

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.

This is pretty cool, to be honest. In fact, this just gave me a nifty idea for something I’m working on.

There’s this awesome ‘framework’ to connect (web) apps with: Zapier
You should check it out, there might be API’s that you can use with a game server.

(There’s IFTTT as well)

[quote] There’s this awesome ‘framework’ to connect (web) apps with: Zapier
You should check it out, there might be API’s that you can use with a game server.

(There’s IFTTT as well) [/quote]

The idea behind this is so users can customize the reporter to meet their own needs. Online frameworks are useful, but aren’t always open sourced. I prefer open-sourced code that allows me to customize it to my needs.

This code, I believe, is pretty straight forward, and should contain no issue(s).
I may, later on, allow RBXDev members to access my “Services” server, and use my API(s). But, this will be later on.

I think it has to be more stable, i tested it and got 7 Mails O_e
And the game only has a baseplate.

Well, that is the second rewrite of GameLogger. The intention of me giving you that code is so you can build your own. But for me, the logger works just fine. .-.

Actually, now that I thought of it, the reporter sends you an email every 2 minutes. This was for testing conditions.

Alright, I’ve ran several tests regarding to how much bandwidth this thing uses, and I have decided to expose an API EXCLUSIVE TO RobloxDev. I will be posting the new script and how to use the API soon.