From 0d1d9bece31f605d4aa68b20f3ecb19cd0db2d3d Mon Sep 17 00:00:00 2001 From: "SND\\weimingzhi_cp" Date: Thu, 13 May 2010 03:40:12 +0000 Subject: added netplay plugin git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@47937 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- plugins/dfnet/unix.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 plugins/dfnet/unix.c (limited to 'plugins/dfnet/unix.c') diff --git a/plugins/dfnet/unix.c b/plugins/dfnet/unix.c new file mode 100644 index 00000000..82f8c1f8 --- /dev/null +++ b/plugins/dfnet/unix.c @@ -0,0 +1,125 @@ +// +// DF Netplay Plugin +// +// Based on netSock 0.2 by linuzappz. +// The Plugin is free source code. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +extern int errno; + +#include "dfnet.h" + +int ExecCfg(const char *arg) { + char cfg[512]; + struct stat buf; + + strcpy(cfg, "cfg/cfgDFNet"); + if (stat(cfg, &buf) != -1) { + strcat(cfg, " "); + strcat(cfg, arg); + return system(cfg); + } + + printf("cfgDFNet file not found!\n"); + return -1; +} + +void SysMessage(const char *fmt, ...) { + va_list list; + char msg[512]; + char cmd[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + sprintf(cmd, "message %s\n", msg); + ExecCfg(cmd); +} + +long sockInit() { + conf.PlayerNum = 0; + tm.tv_sec = 0; + tm.tv_usec = 0; + + return 0; +} + +long sockShutdown() { + return 0; +} + +long sockOpen() { + if (ExecCfg("open") == 0) return -1; + + LoadConf(); + + return 0; +} + +int sockPing() { + char data[32]; + struct timeval tv, tvn; + + memset(data, 0, sizeof(data)); + + gettimeofday(&tv, NULL); + SEND(data, 32, PSE_NET_BLOCKING); + RECV(data, 32, PSE_NET_BLOCKING); + gettimeofday(&tvn, NULL); + + return (tvn.tv_sec - tv.tv_sec) * 1000 + + (tvn.tv_usec - tv.tv_usec) / 1000; +} + +void CALLBACK NETconfigure() { + ExecCfg("configure"); +} + +void CALLBACK NETabout() { + ExecCfg("about"); +} + +pid_t cfgpid = 0; + +void OnWaitDlg_Abort(int num) { + WaitCancel = 1; + cfgpid = 0; +} + +void sockCreateWaitDlg() { + signal(SIGUSR2, OnWaitDlg_Abort); + if ((cfgpid = fork()) == 0) { + execl("cfg/cfgDFNet", "cfgDFNet", "wait", NULL); + exit(0); + } + usleep(100000); +} + +void sockDlgUpdate() { + usleep(100000); +} + +void sockDestroyWaitDlg() { + if (cfgpid > 0) { + kill(cfgpid, SIGKILL); + cfgpid = 0; + } +} + +long timeGetTime() { + struct timeval tv; + + gettimeofday(&tv, NULL); + return (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; +} -- cgit v1.2.3