-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using CrowdControl.Common; | ||
using CrowdControl.Games.Packs; | ||
using ConnectorType = CrowdControl.Common.ConnectorType; | ||
|
||
public class RCTRando : SimpleTCPPack | ||
{ | ||
public override string Host { get; } = "0.0.0.0"; | ||
|
||
public override ushort Port { get; } = 43385; | ||
|
||
public RCTRando(IPlayer player, Func<CrowdControlBlock, bool> responseHandler, Action<object> statusUpdateHandler) : base(player, responseHandler, statusUpdateHandler) { } | ||
|
||
public override Game Game { get; } = new Game(141, "RollerCoaster Tycoon Randomizer", "RCTRando", "PC", ConnectorType.SimpleTCPConnector); | ||
|
||
public override List<Effect> Effects => new List<Effect> | ||
{ | ||
//General Effects | ||
new Effect("Something nice", "nice"), | ||
new Effect("Something mean", "mean") | ||
}; | ||
|
||
//Slider ranges need to be defined | ||
/*public override List<ItemType> ItemTypes => new List<ItemType>(new[] | ||
{ | ||
new ItemType("Money", "money1000", ItemType.Subtype.Slider, "{\"min\":1,\"max\":1000}") | ||
});*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
|
||
let cc_sock: Socket = null; | ||
let cc_good: boolean = false; | ||
|
||
function cc_onError(hadError: boolean) { | ||
console.log('error in Crowd Control connection, attempting to reconnect'); | ||
if(cc_good) { | ||
park.postMessage( | ||
{type: 'blank', text: 'error in Crowd Control connection, attempting to reconnect'} as ParkMessageDesc | ||
); | ||
} | ||
cc_good = false; | ||
cc_connect(); | ||
} | ||
|
||
function cc_onClose(hadError: boolean) { | ||
console.log('Crowd Control connection closed, attempting to reconnect'); | ||
if(cc_good) { | ||
park.postMessage( | ||
{type: 'blank', text: 'Crowd Control connection closed, attempting to reconnect'} as ParkMessageDesc | ||
); | ||
} | ||
cc_good = false; | ||
cc_connect(); | ||
} | ||
|
||
function cc_onData(message: string) { | ||
let data: Object = null; | ||
let resp: Object = null; | ||
|
||
try { | ||
// chop off the null-terminator | ||
while(message[message.length-1] == '\0') | ||
message = message.substring(0, message.length-1); | ||
data = JSON.parse(message); | ||
console.log("Crowd Control received data: ", data); | ||
} catch(e) { | ||
printException('error parsing Crowd Control request JSON: ' + message, e); | ||
} | ||
|
||
try { | ||
resp = cc_req(data); | ||
} catch(e) { | ||
printException('error handling Crowd Control request: ' + message, e); | ||
} | ||
|
||
try { | ||
let r: string = JSON.stringify(resp) + '\0'; | ||
console.log(message, r.length, r); | ||
cc_sock.end(r); | ||
cc_connect(); | ||
} catch(e) { | ||
printException('error sending Crowd Control response to: ' + message, e); | ||
} | ||
} | ||
|
||
function cc_connect() { | ||
if(cc_sock) { | ||
cc_sock.off('error', cc_onError); | ||
cc_sock.off('close', cc_onClose); | ||
cc_sock.destroy(null); | ||
} | ||
|
||
cc_sock = network.createSocket(); | ||
|
||
cc_sock.connect(43385, '127.0.0.1', function() { | ||
console.log('Crowd Control connected!'); | ||
if(!cc_good) { | ||
park.postMessage( | ||
{type: 'blank', text: 'Crowd Control connected!'} as ParkMessageDesc | ||
); | ||
} | ||
cc_good = true; | ||
}); | ||
cc_sock.setNoDelay(true); | ||
|
||
cc_sock.on('error', cc_onError); | ||
cc_sock.on('close', cc_onClose); | ||
cc_sock.on('data', cc_onData); | ||
} | ||
|
||
function init_crowdcontrol() { | ||
cc_connect(); | ||
} | ||
|
||
function cc_req(data) { | ||
const Success = 0; | ||
const Failed = 1; | ||
const NotAvail = 2; | ||
const TempFail = 3; | ||
|
||
park.postMessage( | ||
{type: 'blank', text: data.viewer + ' used ' + data.code} as ParkMessageDesc | ||
); | ||
|
||
return { id: data.id, status: Success }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters