-
Notifications
You must be signed in to change notification settings - Fork 0
hztv
Justin Schwartz edited this page Jun 27, 2020
·
1 revision
Hockey Zone's hztv arena, which plays back replay files on a loop, with a crude on/off time.
This relies on the unreleased Ireplays module which will
$#module hztv
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "replays.h"
$#require global Ireplays
$#arenadata static
FILE *programmingHandle;
char *programmingDescriptor;
int awake;
$#endarenadata
$#attach last
const char *programmingFile = cfg->GetStr(GLOBAL, "HZTvProgramming", arena->name);
if (programmingFile)
{
char filePath[256];
$usearenadata(ad, arena);
ad->awake = TRUE;
snprintf(filePath, sizeof(filePath), "conf/hztv/%s", programmingFile);
ad->programmingHandle = fopen(filePath, "r");
if (ad->programmingHandle)
ml->SetTimer(runNextProgrammingItem, 100, 100, arena, arena);
}
$#endattach
$#detach last
$usearenadata(ad, arena);
$lock();
if (ad->programmingDescriptor)
afree(ad->programmingDescriptor);
if (ad->programmingHandle)
fclose(ad->programmingHandle);
$unlock();
$#enddetach
$#callback arena CB_PLAYERACTION
void cbplayeraction(Player *p, int action, Arena *a)
{
if (action == PA_ENTERARENA)
{
$usearenadata(ad, a);
$lock();
if (!ad->awake && ad->programmingHandle)
{
chat->SendMessage(p, "Replay service is offline presently.");
}
if (ad->programmingDescriptor && *ad->programmingDescriptor && ad->awake)
{
chat->SendMessage(p, "Now playing: %s", ad->programmingDescriptor);
}
$unlock();
}
}
$#endcallback
$#callback arena CB_REPLAYREEL
void cbreplayreel(Arena *a, int remaining)
{
$usearenadata(ad, a);
$lock();
if (!remaining && ad->programmingHandle)
{
ml->SetTimer(runNextProgrammingItem, 100, 100, a, a);
}
$unlock();
}
$#endcallback
int runNextProgrammingItem(void *_a)
{
int returnValue = TRUE;
Arena *a = (Arena *)_a;
$usearenadata(ad, a);
size_t bufferLen;
char *buffer;
ssize_t result;
time_t currentTime;
struct tm *timeStruct;
int curHour;
int sleepHour = cfg->GetInt(GLOBAL, "HZTV", "SleepHour", -1);
int wakeHour = cfg->GetInt(GLOBAL, "HZTV", "WakeHour", -1);
int goToSleep = FALSE;
time(¤tTime);
timeStruct = localtime(¤tTime);
curHour = timeStruct->tm_hour;
if (sleepHour >= 0)
{
if (sleepHour < wakeHour)
{
if (curHour >= sleepHour && curHour < wakeHour)
goToSleep = TRUE;
}
else if (sleepHour > wakeHour)
{
if (curHour >= sleepHour || curHour < wakeHour)
goToSleep = TRUE;
}
if (goToSleep)
{
$lock();
if (ad->awake)
{
ad->awake = FALSE;
chat->SendArenaMessage(a, "Replay service is now in its regularly scheduled sleep period.");
}
$unlock();
return TRUE;
}
}
ad->awake = TRUE;
bufferLen = 0;
buffer = amalloc(sizeof(char) * bufferLen);
result = getline(&buffer, &bufferLen, ad->programmingHandle);
if (result <= 0)
{
$lock();
if (ad->programmingDescriptor)
{
afree(ad->programmingDescriptor);
ad->programmingDescriptor = NULL;
}
$unlock();
rewind(ad->programmingHandle);
returnValue = TRUE;
}
else
{
buffer[strlen(buffer)-1] = '\0';
if (buffer[0] == '"')
{
chat->SendArenaMessage(a, "%s", buffer + 1);
returnValue = TRUE;
}
else if (buffer[0] == ':')
{
$lock();
if (ad->programmingDescriptor)
afree(ad->programmingDescriptor);
ad->programmingDescriptor = astrdup(buffer + 1);
$unlock();
chat->SendArenaMessage(a, "Now up: %s", ad->programmingDescriptor);
returnValue = TRUE;
}
else if (buffer[0] == '*')
{
LinkedList *list = replays->ListReplays(buffer + 1);
Link *link;
replay_info *ri;
FOR_EACH(list, ri, link)
{
if (strstr(ri->buffer, "buffer.rec")
|| strstr(ri->buffer, "_0.rec")
|| strstr(ri->buffer, "_1.rec"))
{
afree(ri);
LLRemove(list, ri);
}
}
if (!replays->StartReplayReel(a, list))
{
replays->FreeReplayList(list);
returnValue = TRUE;
}
else
{
returnValue = FALSE;
}
}
else
{
//TODO: implement replays ability to read a list of replays.
returnValue = TRUE;
}
}
afree(buffer);
return returnValue;
}
"RSHL Playoffs, Season 16
"The season had 10 teams, 6 of which made the playoffs:
"Baby Seal Killers, Breakaway, Dirtybirds, Reppowarriors, Scorgasms, and Thunder Wolves
"Dirtybirds and Reppowarriors, the two highest seeds, had a bye, but had the option to a challenge game.
"The winner of the challenge would be able to choose which of the two remaining teams from the quarterfinals they would face.
:Season 16 - Challenge Game (non-elimination): Dirtybirds at Reppowarriors
* hockey/s44/1991
"Quarterfinals: (3)Baby Seal Killers vs (6)Breakaway and (4)Scorgasms vs (5)Thunder Wolves
:Season 16 - BA @ BSK (RSHL Quarterfinals, Game 1)
* hockey/s44/1980
"BA wins 5-3
:Season 16 - TW @ SG (RSHL Quarterfinals, Game 1)
* hockey/s44/1979
"TW wins 4-2
:Season 16 - BSK @ BA (RSHL Quarterfinals, Game 2, BSK faces elimination)
* hockey/s44/1981
"BSK wins 7-1
:Season 16 - SG @ TW (RSHL Quarterfinals, Game 2, SG faces elimination)
* hockey/s44/1982
"SG wins 6-3
:Season 16 - BA @ BSK (RSHL Quarterfinals, Game 3, Series decision)
* hockey/s44/1983
"BSK wins 7-4 and takes the series
:Season 16 - TW @ SG (RSHL Quarterfinals, Game 3, Series decision)
* hockey/s44/1984
"TW MERCIES SG, 11-1, and takes the series
"Semifinals: (1)Reppowarriors vs (5)Thunder Wolves and (2)Dirtybirds vs (3)Baby Seal Killers
:Season 16 - TW @ RW (RSHL Semifinals, Game 1)
* hockey/s44/1995
"RW wins 4-3
:Season 16 - BSK @ DB (RSHL Semifinals, Game 1)
* hockey/s44/1994
"DB wins 3-2
:Season 16 - RW @ TW (RSHL Semifinals, Game 2, TW faces elimination)
* hockey/s44/1997
"RW wins 5-3, takes the series, and advances to the finals
:Season 16 - DB @ BSK (RSHL Semifinals, Game 2, BSK faces elimination)
* hockey/s44/1996
"BSK wins 6-2
:Season 16 - BSK @ DB (RSHL Semifinals, Game 3, Series decision)
* hockey/s44/1999
"DB wins 7-3, takes the series, and advances to the finals
"Blackie Cup Finals: (1)Reppowarriors vs (2)Dirtybirds
:Season 16 - DB @ RW (Blackie Cup Finals, Game 1)
* hockey/s44/2003full
* hockey/s44/2003
"RW wins 5-3, leads the series 1-0
:Season 16 - RW @ DB (Blackie Cup Finals, Game 2, RW leads the series 1-0)
* hockey/s44/2004full
* hockey/s44/2004
"RW wins 3-2, leads the series 2-0
:Season 16 - DB @ RW (Blackie Cup Finals, Game 3, RW leads the series 2-0, DB faces elimination)
* hockey/s44/2005full
* hockey/s44/2005
"DB wins 5-4, trails in the series 2-1
:Season 16 - RW @ DB (Blackie Cup Finals, Game 4, RW leads the series 2-1, DB faces elimination)
* hockey/s44/2006full
* hockey/s44/2006
"DB wins 2-1, and ties up the series
:Season 16 - DB @ RW (Blackie Cup Finals, Game 5, Series tied 2-2, Championship decision game!)
* hockey/s44/2007full
* hockey/s44/2007
"DB wins 4-2
"Dirtybirds are the RSHL Season 16 Champions!
/* called when a recording file finishes during ReplayReel */
#define CB_REPLAYREEL "replayreel"
typedef int (*ReplayReelCB)(Arena *a, int remaining);
typedef struct Ireplays
{
INTERFACE_HEAD_DECL
LinkedList * (*ListReplays)(const char *path); //returns a list of files in a given path
void (*FreeReplayList)(LinkedList *list); //frees results from ListReplays
int (*StartReplayReel)(Arena *a, LinkedList *reel); //invokves record.c to play back replay files from the list
int (*StopReplayReel)(Arena *a); //cancels the replay reel
} Ireplays;