Find User here you can look for a user

MC2 News Server in PHP complete code example

1y
#1
To answer questions that came up in-game about creating an MC2 news server, here is a complete .php script that you can use as a news server endpoint. Should be enough to get you started and you can customize it from there as you see fit.


<?php
header("access-control-allow-origin: *");
header("access-control-allow-headers: Content-Type");

$json = file_get_contents('php://input');
$data = json_decode($json);

if($data == null || $data == false || !property_exists($data, "req")) {
exit();
}

$requestId = $data->req;

if($requestId == "networkinfo") {
$resData = new stdClass();

$resData->networkName = "My News Network";
$resData->networkNameShort = "MNN";
$resData->logoBackground = "#ff0000";
$resData->logoText = "#00ff00";
$resData->logoStroke = "#000000";

$resData->taglines = array();

$resData->taglines[] = "My News Network - It's Good Stuff!";
$resData->taglines[] = "You are watching My News Network!";

$cannedResponses = new stdClass();

$cannedResponses->healthcrisis = array();
$cannedResponses->healthcrisis[] = "put your news headline here 1";

$cannedResponses->techunlock = array();
$cannedResponses->techunlock[] = "put your news headline here 1";

$cannedResponses->highunemp = array();
$cannedResponses->highunemp[] = "put your news headline here 1";
$cannedResponses->highunemp[] = "put your news headline here 2";

$cannedResponses->ollargestsettlement = array();
$cannedResponses->ollargestsettlement[] = "put your news headline here";
$cannedResponses->ollargestsettlement[] = "put your news headline here 2";

$cannedResponses->starvation = array();
$cannedResponses->starvation[] = "put your news headline here";
$cannedResponses->starvation[] = "put your news headline here 2";

$cannedResponses->lowapproval = array();
$cannedResponses->lowapproval[] = "put your news headline here";

$cannedResponses->lowsecurity = array();
$cannedResponses->lowsecurity[] = "put your news headline here";
$cannedResponses->lowsecurity[] = "put your news headline here 2";

$cannedResponses->lowentertainment = array();
$cannedResponses->lowentertainment[] = "put your news headline here";
$cannedResponses->lowentertainment[] = "put your news headline here 2";

$cannedResponses->loweducation = array();
$cannedResponses->loweducation[] = "put your news headline here";
$cannedResponses->loweducation[] = "put your news headline here 2";

$resData->responses = $cannedResponses;

echo json_encode($resData);
}
?>

This should be enough information to get a PHP script up and running. You need an https endpoint, you can get a free ssl cert using certbot. For a list of all of the variables that the news headline responses accept, see this thread.

Note that I did not run this code first to see if it works, so there might be typos or syntax errors, so just use your brain while implementing!

Hope that helps!
Owner of Ape Apps, LLC
Welcome
Ape Apps, LLC is an independent software development company founded in 2010 by Brandon Stecklein. Over the years, Ape Apps has published over 400 apps and games across various platforms. You can get in touch with Brandon on Twitter or by leaving a post on his wall @bastecklein
App of the Day