Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f75ddaff8 |
No files matched your search
@@ -1,153 +0,0 @@
|
|||||||
import java.io.PrintStream;
|
|
||||||
import java.net.*;
|
|
||||||
|
|
||||||
class Connection extends Thread
|
|
||||||
implements Runnable
|
|
||||||
{
|
|
||||||
|
|
||||||
Connection(vacemu vacemu1, DatagramPacket datagrampacket)
|
|
||||||
{
|
|
||||||
receivedPacket = null;
|
|
||||||
Parent = vacemu1;
|
|
||||||
Address = datagrampacket.getAddress();
|
|
||||||
Port = datagrampacket.getPort();
|
|
||||||
P = datagrampacket;
|
|
||||||
}
|
|
||||||
|
|
||||||
void send(DatagramPacket datagrampacket)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Parent.S.send(datagrampacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
DatagramPacket receive()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(50000L);
|
|
||||||
throw new Exception("Receive timed out");
|
|
||||||
}
|
|
||||||
catch(InterruptedException interruptedexception)
|
|
||||||
{
|
|
||||||
return receivedPacket;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void packet(DatagramPacket datagrampacket)
|
|
||||||
{
|
|
||||||
receivedPacket = datagrampacket;
|
|
||||||
interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Req req = new Req(P);
|
|
||||||
if(!"CHALLENGE".equals(req.Cmd))
|
|
||||||
{
|
|
||||||
ReqCheckAccess reqcheckaccess = new ReqCheckAccess(P);
|
|
||||||
if(((Req) (reqcheckaccess)).legal)
|
|
||||||
{
|
|
||||||
System.out.println(" 'Check access'");
|
|
||||||
byte abyte0[] = vacemu.Cmd_AccessGranted(reqcheckaccess.Id, (byte)1);
|
|
||||||
send(new DatagramPacket(abyte0, abyte0.length, P.getAddress(), P.getPort()));
|
|
||||||
Parent.closeConnection(this);
|
|
||||||
return;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
byte abyte1[] = vacemu.Cmd_Abort("error");
|
|
||||||
send(new DatagramPacket(abyte1, abyte1.length, P.getAddress(), P.getPort()));
|
|
||||||
throw new Exception("Protocol violation");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
byte abyte2[] = vacemu.Cmd_Accept(Module.Id);
|
|
||||||
send(new DatagramPacket(abyte2, abyte2.length, P.getAddress(), P.getPort()));
|
|
||||||
abyte2 = new byte[256];
|
|
||||||
P = receive();
|
|
||||||
ReqGet reqget = new ReqGet(P);
|
|
||||||
if(!((Req) (reqget)).legal)
|
|
||||||
{
|
|
||||||
System.out.println("Invalid GET request from " + P.getAddress() + " :");
|
|
||||||
vacemu.Print(P);
|
|
||||||
throw new Exception("Protocol violation");
|
|
||||||
}
|
|
||||||
System.out.print(" Request for file " + reqget.FileName);
|
|
||||||
if(vacemu.TestModuleDir.equals(reqget.TestDir))
|
|
||||||
System.out.print(" [beta]");
|
|
||||||
System.out.println();
|
|
||||||
if(Module.Id != reqget.Id)
|
|
||||||
{
|
|
||||||
abyte2 = vacemu.Cmd_Abort("Challenge error");
|
|
||||||
send(new DatagramPacket(abyte2, abyte2.length, P.getAddress(), P.getPort()));
|
|
||||||
throw new Exception("Module order error: request id=" + reqget.Id + " while expecting id=" + Module.Id);
|
|
||||||
}
|
|
||||||
if(!Character.isLetterOrDigit(reqget.FileName.charAt(0)))
|
|
||||||
{
|
|
||||||
System.out.println(" ! Attempt to get file " + reqget.FileName);
|
|
||||||
Parent.closeConnection(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Module module = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
module = new Module(reqget.FileName);
|
|
||||||
}
|
|
||||||
catch(Exception exception1)
|
|
||||||
{
|
|
||||||
abyte2 = vacemu.Cmd_Abort("file not found");
|
|
||||||
send(new DatagramPacket(abyte2, abyte2.length, P.getAddress(), P.getPort()));
|
|
||||||
System.out.println(" ! File not found: " + reqget.FileName);
|
|
||||||
Parent.closeConnection(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
abyte2 = vacemu.Cmd_File(module.Size, module.Header);
|
|
||||||
send(new DatagramPacket(abyte2, abyte2.length, P.getAddress(), P.getPort()));
|
|
||||||
do
|
|
||||||
{
|
|
||||||
P = receive();
|
|
||||||
ReqNext reqnext = new ReqNext(P);
|
|
||||||
if("ABORT".equals(((Req) (reqnext)).Cmd))
|
|
||||||
{
|
|
||||||
System.out.println(" Connection closed");
|
|
||||||
Parent.closeConnection(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!((Req) (reqnext)).legal || reqnext.Pos < 0 || reqnext.Pos > module.Size)
|
|
||||||
{
|
|
||||||
byte abyte3[] = vacemu.Cmd_Abort("error");
|
|
||||||
send(new DatagramPacket(abyte3, abyte3.length, P.getAddress(), P.getPort()));
|
|
||||||
throw new Exception("Protocol violation: " + ((Req) (reqnext)).Cmd);
|
|
||||||
}
|
|
||||||
if(reqnext.Pos == module.Size)
|
|
||||||
{
|
|
||||||
byte abyte4[] = vacemu.Cmd_Finish();
|
|
||||||
send(new DatagramPacket(abyte4, abyte4.length, P.getAddress(), P.getPort()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int i = module.Size - reqnext.Pos;
|
|
||||||
if(i > 1024)
|
|
||||||
i = 1024;
|
|
||||||
byte abyte6[] = new byte[i];
|
|
||||||
System.arraycopy(module.Data, reqnext.Pos, abyte6, 0, i);
|
|
||||||
byte abyte5[] = vacemu.Cmd_Block(abyte6);
|
|
||||||
send(new DatagramPacket(abyte5, abyte5.length, P.getAddress(), P.getPort()));
|
|
||||||
} while(true);
|
|
||||||
System.out.println(" File " + module.Name + " transfered");
|
|
||||||
Parent.closeConnection(this);
|
|
||||||
}
|
|
||||||
catch(Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
Parent.closeConnection(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vacemu Parent;
|
|
||||||
InetAddress Address;
|
|
||||||
int Port;
|
|
||||||
DatagramPacket receivedPacket;
|
|
||||||
DatagramPacket P;
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Main-Class: vacemu
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
.PHONY: all clean
|
|
||||||
|
|
||||||
MAIN=vacemu
|
|
||||||
|
|
||||||
all: $(MAIN)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) *.o *.class $(MAIN) $(MAIN).jar
|
|
||||||
|
|
||||||
|
|
||||||
$(MAIN): $(patsubst %.java,%.o,$(wildcard *.java))
|
|
||||||
|
|
||||||
$(MAIN).jar: $(MAIN).class
|
|
||||||
|
|
||||||
|
|
||||||
%: %.o
|
|
||||||
gcj --main=$@ $^ -o $@
|
|
||||||
|
|
||||||
%.o: %.java
|
|
||||||
gcj -c $<
|
|
||||||
|
|
||||||
%.jar: %.class
|
|
||||||
jar cfm $@ MANIFEST.MF $(patsubst %.java,%.class,$(wildcard *.java))
|
|
||||||
|
|
||||||
$(MAIN).class: $(wildcard *.java)
|
|
||||||
javac $^
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
import java.io.*;
|
|
||||||
|
|
||||||
class Module
|
|
||||||
{
|
|
||||||
|
|
||||||
Module()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Module(String s)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
this(new DataInputStream(new FileInputStream(s)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Module(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Name = datainputstream.readUTF();
|
|
||||||
int i = datainputstream.readInt();
|
|
||||||
Header = new byte[i];
|
|
||||||
datainputstream.read(Header);
|
|
||||||
i = datainputstream.readInt();
|
|
||||||
Data = new byte[i];
|
|
||||||
Size = i;
|
|
||||||
datainputstream.read(Data);
|
|
||||||
encode(Data, Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
int i = Name.lastIndexOf('/');
|
|
||||||
if(i != -1)
|
|
||||||
{
|
|
||||||
String s = Name.substring(0, i);
|
|
||||||
(new File(s)).mkdirs();
|
|
||||||
}
|
|
||||||
write(new DataOutputStream(new FileOutputStream(Name)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void write(DataOutputStream dataoutputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
dataoutputstream.writeUTF(Name);
|
|
||||||
dataoutputstream.writeInt(Header.length);
|
|
||||||
dataoutputstream.write(Header);
|
|
||||||
dataoutputstream.writeInt(Data.length);
|
|
||||||
dataoutputstream.write(Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void decode(byte abyte0[], int i)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < abyte0.length; j += 1024)
|
|
||||||
{
|
|
||||||
int k = abyte0.length - j;
|
|
||||||
if(k > 1024)
|
|
||||||
k = 1024;
|
|
||||||
decode(abyte0, i, j, k);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void encode(byte abyte0[], int i)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < abyte0.length; j += 1024)
|
|
||||||
{
|
|
||||||
int k = abyte0.length - j;
|
|
||||||
if(k > 1024)
|
|
||||||
k = 1024;
|
|
||||||
encode(abyte0, i, j, k);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void decode(byte abyte0[], int i, int j, int k)
|
|
||||||
{
|
|
||||||
int l = ~i;
|
|
||||||
int i1 = 0;
|
|
||||||
for(int j1 = j; j1 + 3 < j + k; j1 += 4)
|
|
||||||
{
|
|
||||||
abyte0[j1] ^= i & 0xff;
|
|
||||||
abyte0[j1 + 1] ^= i >> 8 & 0xff;
|
|
||||||
abyte0[j1 + 2] ^= i >> 16 & 0xff;
|
|
||||||
abyte0[j1 + 3] ^= i >> 24 & 0xff;
|
|
||||||
abyte0[j1] ^= pattern[i1 + 0 & 0xf] | 0xa5;
|
|
||||||
abyte0[j1 + 1] ^= pattern[i1 + 1 & 0xf] | 0xa7;
|
|
||||||
abyte0[j1 + 2] ^= pattern[i1 + 2 & 0xf] | 0xad;
|
|
||||||
abyte0[j1 + 3] ^= pattern[i1 + 3 & 0xf] | 0xbf;
|
|
||||||
byte byte0 = abyte0[j1];
|
|
||||||
byte byte1 = abyte0[j1 + 1];
|
|
||||||
byte byte2 = abyte0[j1 + 2];
|
|
||||||
byte byte3 = abyte0[j1 + 3];
|
|
||||||
abyte0[j1] = byte3;
|
|
||||||
abyte0[j1 + 1] = byte2;
|
|
||||||
abyte0[j1 + 2] = byte1;
|
|
||||||
abyte0[j1 + 3] = byte0;
|
|
||||||
abyte0[j1] ^= l & 0xff;
|
|
||||||
abyte0[j1 + 1] ^= l >> 8 & 0xff;
|
|
||||||
abyte0[j1 + 2] ^= l >> 16 & 0xff;
|
|
||||||
abyte0[j1 + 3] ^= l >> 24 & 0xff;
|
|
||||||
i1++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void encode(byte abyte0[], int i, int j, int k)
|
|
||||||
{
|
|
||||||
int l = ~i;
|
|
||||||
int i1 = 0;
|
|
||||||
for(int j1 = j; j1 + 3 < j + k; j1 += 4)
|
|
||||||
{
|
|
||||||
abyte0[j1] ^= l & 0xff;
|
|
||||||
abyte0[j1 + 1] ^= l >> 8 & 0xff;
|
|
||||||
abyte0[j1 + 2] ^= l >> 16 & 0xff;
|
|
||||||
abyte0[j1 + 3] ^= l >> 24 & 0xff;
|
|
||||||
byte byte0 = abyte0[j1];
|
|
||||||
byte byte1 = abyte0[j1 + 1];
|
|
||||||
byte byte2 = abyte0[j1 + 2];
|
|
||||||
byte byte3 = abyte0[j1 + 3];
|
|
||||||
abyte0[j1] = byte3;
|
|
||||||
abyte0[j1 + 1] = byte2;
|
|
||||||
abyte0[j1 + 2] = byte1;
|
|
||||||
abyte0[j1 + 3] = byte0;
|
|
||||||
abyte0[j1] ^= pattern[i1 + 0 & 0xf] | 0xa5;
|
|
||||||
abyte0[j1 + 1] ^= pattern[i1 + 1 & 0xf] | 0xa7;
|
|
||||||
abyte0[j1 + 2] ^= pattern[i1 + 2 & 0xf] | 0xad;
|
|
||||||
abyte0[j1 + 3] ^= pattern[i1 + 3 & 0xf] | 0xbf;
|
|
||||||
abyte0[j1] ^= i & 0xff;
|
|
||||||
abyte0[j1 + 1] ^= i >> 8 & 0xff;
|
|
||||||
abyte0[j1 + 2] ^= i >> 16 & 0xff;
|
|
||||||
abyte0[j1 + 3] ^= i >> 24 & 0xff;
|
|
||||||
i1++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean compareHeader(Module module)
|
|
||||||
{
|
|
||||||
if(module.Header == null || Header == null || Header.length != module.Header.length || Header.length < 20)
|
|
||||||
return false;
|
|
||||||
for(int i = 0; i < 20; i++)
|
|
||||||
if(Header[i] != module.Header[i])
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String Name;
|
|
||||||
int Size;
|
|
||||||
byte Header[];
|
|
||||||
byte Data[];
|
|
||||||
static int Id = 0x12345678;
|
|
||||||
static byte pattern[] = {
|
|
||||||
5, 97, 122, -19, 27, -54, 13, -101, 74, -15,
|
|
||||||
100, -57, -75, -114, -33, -96
|
|
||||||
};
|
|
||||||
static byte pattern2[] = {
|
|
||||||
32, 7, 19, 97, 3, 69, 23, 114, 10, 45,
|
|
||||||
72, 12, 74, 18, -87, -75
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
import java.io.*;
|
|
||||||
import java.net.DatagramPacket;
|
|
||||||
|
|
||||||
class Req
|
|
||||||
{
|
|
||||||
|
|
||||||
static byte[] getBuf(DatagramPacket datagrampacket)
|
|
||||||
{
|
|
||||||
byte abyte0[] = new byte[datagrampacket.getLength()];
|
|
||||||
System.arraycopy(datagrampacket.getData(), 0, abyte0, 0, datagrampacket.getLength());
|
|
||||||
return abyte0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Req(DatagramPacket datagrampacket)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
this(getBuf(datagrampacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
Req(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
read(new DataInputStream(new ByteArrayInputStream(abyte0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
int readInt(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
return datainputstream.readByte() & 0xff | (datainputstream.readByte() & 0xff) << 8 | (datainputstream.readByte() & 0xff) << 16 | (datainputstream.readByte() & 0xff) << 24;
|
|
||||||
}
|
|
||||||
|
|
||||||
short readShort(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
return (short)(datainputstream.readByte() & 0xff | (datainputstream.readByte() & 0xff) << 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
String readString(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
byte abyte0[] = new byte[256];
|
|
||||||
int i = 0;
|
|
||||||
for(byte byte0 = 1; byte0 != 0;)
|
|
||||||
{
|
|
||||||
byte0 = datainputstream.readByte();
|
|
||||||
abyte0[i] = byte0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new String(abyte0, 0, i - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
A = readInt(datainputstream);
|
|
||||||
B = datainputstream.readByte();
|
|
||||||
C = datainputstream.readByte();
|
|
||||||
if(B != 77)
|
|
||||||
Cmd = readString(datainputstream);
|
|
||||||
else
|
|
||||||
Cmd = "CheckAccess";
|
|
||||||
legal = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print()
|
|
||||||
{
|
|
||||||
System.out.println("A = " + A);
|
|
||||||
System.out.println("B = " + B);
|
|
||||||
System.out.println("C = " + C);
|
|
||||||
System.out.println("Cmd = " + Cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
int A;
|
|
||||||
int B;
|
|
||||||
int C;
|
|
||||||
String Cmd;
|
|
||||||
boolean legal;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
class ReqAccept extends Req
|
|
||||||
{
|
|
||||||
|
|
||||||
ReqAccept(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super(abyte0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.read(datainputstream);
|
|
||||||
if("ACCEPT".equals(super.Cmd))
|
|
||||||
Id = readInt(datainputstream);
|
|
||||||
else
|
|
||||||
super.legal = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print()
|
|
||||||
{
|
|
||||||
super.print();
|
|
||||||
System.out.println("Id = " + Integer.toHexString(Id));
|
|
||||||
}
|
|
||||||
|
|
||||||
int Id;
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
class ReqBlock extends Req
|
|
||||||
{
|
|
||||||
|
|
||||||
ReqBlock(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super(abyte0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.read(datainputstream);
|
|
||||||
if("BLOCK".equals(super.Cmd))
|
|
||||||
{
|
|
||||||
Size = readShort(datainputstream);
|
|
||||||
Data = new byte[Size];
|
|
||||||
datainputstream.read(Data);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
super.legal = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void print()
|
|
||||||
{
|
|
||||||
super.print();
|
|
||||||
System.out.println("Size = " + Size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Size;
|
|
||||||
byte Data[];
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.DatagramPacket;
|
|
||||||
|
|
||||||
class ReqCheckAccess extends Req
|
|
||||||
{
|
|
||||||
|
|
||||||
ReqCheckAccess(DatagramPacket datagrampacket)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
this(Req.getBuf(datagrampacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
ReqCheckAccess(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super(abyte0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.A = readInt(datainputstream);
|
|
||||||
super.B = datainputstream.readByte();
|
|
||||||
super.C = datainputstream.readByte();
|
|
||||||
super.legal = super.A == -1 && super.B == 77 && super.C == 0;
|
|
||||||
Id = readInt(datainputstream);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print()
|
|
||||||
{
|
|
||||||
super.print();
|
|
||||||
System.out.println("Id = " + Integer.toHexString(Id));
|
|
||||||
}
|
|
||||||
|
|
||||||
int Id;
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
class ReqFile extends Req
|
|
||||||
{
|
|
||||||
|
|
||||||
ReqFile(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super(abyte0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.read(datainputstream);
|
|
||||||
if("FILE".equals(super.Cmd))
|
|
||||||
{
|
|
||||||
Size = readInt(datainputstream);
|
|
||||||
Header = new byte[34];
|
|
||||||
datainputstream.read(Header);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
super.legal = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintArr(byte abyte0[], int i)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < i; j++)
|
|
||||||
{
|
|
||||||
byte byte0 = abyte0[j];
|
|
||||||
if(byte0 < 32 || byte0 > 122)
|
|
||||||
System.out.print(Integer.toHexString(byte0 & 0xff) + " ");
|
|
||||||
else
|
|
||||||
System.out.print("'" + (char)byte0 + "' ");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
void print()
|
|
||||||
{
|
|
||||||
super.print();
|
|
||||||
System.out.println("Size = " + Size + " " + Integer.toHexString(Size));
|
|
||||||
System.out.println("Header size=" + Header.length);
|
|
||||||
PrintArr(Header, Header.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Size;
|
|
||||||
byte Header[];
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.DatagramPacket;
|
|
||||||
|
|
||||||
class ReqGet extends Req
|
|
||||||
{
|
|
||||||
|
|
||||||
ReqGet(DatagramPacket datagrampacket)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
this(Req.getBuf(datagrampacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
ReqGet(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super(abyte0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.read(datainputstream);
|
|
||||||
if("GET".equals(super.Cmd))
|
|
||||||
{
|
|
||||||
Id = readInt(datainputstream);
|
|
||||||
FileName = readString(datainputstream);
|
|
||||||
D = readInt(datainputstream);
|
|
||||||
TestDir = readString(datainputstream);
|
|
||||||
Random = new int[3];
|
|
||||||
Random[0] = Random[1] = Random[2] = 0;
|
|
||||||
int i = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for(i = 0; i < 3; i++)
|
|
||||||
Random[i] = readInt(datainputstream);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(Exception exception)
|
|
||||||
{
|
|
||||||
System.out.println(" Warning: read " + i + " randoms from 3");
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
super.legal = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void print()
|
|
||||||
{
|
|
||||||
super.print();
|
|
||||||
System.out.println("Id = " + Id);
|
|
||||||
System.out.println("FileName = " + FileName);
|
|
||||||
System.out.println("D = " + D);
|
|
||||||
System.out.println("TestDir = " + TestDir);
|
|
||||||
System.out.println("Random1 = " + Random[0]);
|
|
||||||
System.out.println("Random2 = " + Random[1]);
|
|
||||||
System.out.println("Random3 = " + Random[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Id;
|
|
||||||
String FileName;
|
|
||||||
int D;
|
|
||||||
String TestDir;
|
|
||||||
int Random[];
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.DatagramPacket;
|
|
||||||
|
|
||||||
class ReqNext extends Req
|
|
||||||
{
|
|
||||||
|
|
||||||
ReqNext(DatagramPacket datagrampacket)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
this(Req.getBuf(datagrampacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
ReqNext(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super(abyte0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInputStream datainputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.read(datainputstream);
|
|
||||||
if("NEXT".equals(super.Cmd))
|
|
||||||
Pos = readInt(datainputstream);
|
|
||||||
else
|
|
||||||
super.legal = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print()
|
|
||||||
{
|
|
||||||
super.print();
|
|
||||||
System.out.println("Pos = " + Pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Pos;
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#!/usr/bin/perl
|
|
||||||
|
|
||||||
# Small VAC auth server by beast.
|
|
||||||
|
|
||||||
use IO::Socket;
|
|
||||||
use POSIX 'strftime';
|
|
||||||
|
|
||||||
$lport = 27012;
|
|
||||||
|
|
||||||
srand;
|
|
||||||
while() {
|
|
||||||
$server = IO::Socket::INET->new(Proto=>'udp', LocalPort=>$lport) || die "Error";
|
|
||||||
$addr = $server->recv($data, 128);
|
|
||||||
$server->close();
|
|
||||||
($size, $port, @_) = unpack("nnC4", $addr);
|
|
||||||
$addr = join(".", @_);
|
|
||||||
printf strftime "%d/%m/%Y - %H:%M:%S: VAC auth request from $addr:$port\n", localtime;
|
|
||||||
|
|
||||||
($ffff, $type, $auth) = unpack("NSN", $data);
|
|
||||||
|
|
||||||
if ($ffff == 0xFFFFFFFF && $type == 0x4D) {
|
|
||||||
$rndv = int(rand(0xFFFF));
|
|
||||||
$data = pack("NSNSNS", 0xFFFFFFFF, 0x4E, $auth, 0x01, 0x00000000, $rndv);
|
|
||||||
$server = IO::Socket::INET->new(Proto=>'udp', LocalPort=>$lport, PeerAddr=>$addr, PeerPort=>$port) || die "Error";
|
|
||||||
$server->send($data);
|
|
||||||
$server->close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,520 +0,0 @@
|
|||||||
/*
|
|
||||||
* Half-Life secure server emulator by Tomas Janousek <tomi@nomi.cz>
|
|
||||||
*
|
|
||||||
* Based on JAD-decompiled sources of
|
|
||||||
* Secure server emulator v1.3.2 by Shtirlits boris@uchcom.botik.ru
|
|
||||||
* ( http://uchcom.botik.ru/boris/cs/index_e.html )
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
public class vacemu
|
|
||||||
{
|
|
||||||
|
|
||||||
vacemu()
|
|
||||||
{
|
|
||||||
S = null;
|
|
||||||
Connections = new Hashtable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void serv(int i)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
S = new DatagramSocket(i);
|
|
||||||
S.setSoTimeout(5000);
|
|
||||||
}
|
|
||||||
catch(Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
if(S != null)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
catch(Exception exception2) { }
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.println(DF.format(new Date()) + "Waiting connections ...");
|
|
||||||
do
|
|
||||||
try
|
|
||||||
{
|
|
||||||
buf = new byte[256];
|
|
||||||
P = new DatagramPacket(buf, buf.length);
|
|
||||||
S.receive(P);
|
|
||||||
Connection connection = (Connection)Connections.get(P.getAddress().toString() + P.getPort());
|
|
||||||
if(connection == null)
|
|
||||||
{
|
|
||||||
System.out.println(DF.format(new Date()) + "Connect from " + " (" + P.getAddress().getHostAddress() + ")");
|
|
||||||
connection = new Connection(this, P);
|
|
||||||
Connections.put(P.getAddress().toString() + P.getPort(), connection);
|
|
||||||
connection.start();
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
connection.packet(P);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception exception1) { }
|
|
||||||
while(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void closeConnection(Connection connection)
|
|
||||||
{
|
|
||||||
Connections.remove(connection.Address.toString() + connection.Port);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void writeShort(int i, DataOutputStream dataoutputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
dataoutputstream.writeByte(i & 0xff);
|
|
||||||
dataoutputstream.writeByte(i >> 8 & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void writeInt(int i, DataOutputStream dataoutputstream)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
dataoutputstream.writeByte(i & 0xff);
|
|
||||||
dataoutputstream.writeByte(i >> 8 & 0xff);
|
|
||||||
dataoutputstream.writeByte(i >> 16 & 0xff);
|
|
||||||
dataoutputstream.writeByte(i >> 24 & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_Challenge()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(74);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("CHALLENGE");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_Accept(int i)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(75);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("ACCEPT");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeInt(i, dataoutputstream);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_Abort(String s)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(75);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("ABORT");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes(s);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_Finish()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(75);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("FINISH");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_File(int i, byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(75);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("FILE");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeInt(i, dataoutputstream);
|
|
||||||
dataoutputstream.write(abyte0, 0, abyte0.length);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_Next(int i)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(74);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("NEXT");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeInt(i, dataoutputstream);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_Block(byte abyte0[])
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(75);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("BLOCK");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeShort(abyte0.length, dataoutputstream);
|
|
||||||
dataoutputstream.write(abyte0, 0, abyte0.length);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_Get(String s, int i, boolean flag)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
int j = (int)(Math.random() * 2147483647D);
|
|
||||||
int k = (int)(Math.random() * 2147483647D);
|
|
||||||
int l = (int)(Math.random() * 2147483647D);
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(74);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeBytes("GET");
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeInt(i, dataoutputstream);
|
|
||||||
dataoutputstream.writeBytes(s);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeInt(0x43210004, dataoutputstream);
|
|
||||||
if(flag)
|
|
||||||
dataoutputstream.writeBytes(TestModuleDir);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeInt(j, dataoutputstream);
|
|
||||||
writeInt(k, dataoutputstream);
|
|
||||||
writeInt(l, dataoutputstream);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] Cmd_AccessGranted(int i, byte byte0)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
|
|
||||||
writeInt(-1, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(78);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
writeInt(i, dataoutputstream);
|
|
||||||
dataoutputstream.writeByte(byte0);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
dataoutputstream.writeByte(0);
|
|
||||||
return bytearrayoutputstream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintHexArr(byte abyte0[], int i)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < i; j++)
|
|
||||||
System.out.print(Integer.toHexString(abyte0[j] & 0xff) + " ");
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintArr(byte abyte0[], int i)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < i; j++)
|
|
||||||
{
|
|
||||||
byte byte0 = abyte0[j];
|
|
||||||
if(byte0 < 32 || byte0 > 122)
|
|
||||||
System.out.print(Integer.toHexString(byte0 & 0xff) + " ");
|
|
||||||
else
|
|
||||||
System.out.print("'" + (char)byte0 + "' ");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Print(DatagramPacket datagrampacket)
|
|
||||||
{
|
|
||||||
PrintArr(datagrampacket.getData(), datagrampacket.getLength());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintArr(byte abyte0[])
|
|
||||||
{
|
|
||||||
PrintArr(abyte0, abyte0.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int Challenge(DatagramSocket datagramsocket, InetAddress inetaddress, int i)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
System.out.print("Sending the challenge request...");
|
|
||||||
byte abyte0[] = Cmd_Challenge();
|
|
||||||
datagramsocket.send(new DatagramPacket(abyte0, abyte0.length, inetaddress, i));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(50L);
|
|
||||||
}
|
|
||||||
catch(Exception exception) { }
|
|
||||||
abyte0 = new byte[256];
|
|
||||||
DatagramPacket datagrampacket = new DatagramPacket(abyte0, abyte0.length);
|
|
||||||
datagramsocket.receive(datagrampacket);
|
|
||||||
ReqAccept reqaccept = new ReqAccept(abyte0);
|
|
||||||
if(!((Req) (reqaccept)).legal)
|
|
||||||
{
|
|
||||||
System.out.println("Connection rejected");
|
|
||||||
Print(datagrampacket);
|
|
||||||
throw new Exception();
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
System.out.println(" ok");
|
|
||||||
return reqaccept.Id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Module LoadModule(DatagramSocket datagramsocket, InetAddress inetaddress, int i, String s, boolean flag)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Module module = new Module();
|
|
||||||
module.Name = s;
|
|
||||||
int j = Challenge(datagramsocket, inetaddress, i);
|
|
||||||
System.out.print("Sending the get request, file '" + s);
|
|
||||||
if(flag)
|
|
||||||
System.out.print(" [beta] ");
|
|
||||||
byte abyte0[] = Cmd_Get(s, j, flag);
|
|
||||||
datagramsocket.send(new DatagramPacket(abyte0, abyte0.length, inetaddress, i));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(50L);
|
|
||||||
}
|
|
||||||
catch(Exception exception2) { }
|
|
||||||
System.out.print("' ...");
|
|
||||||
abyte0 = new byte[256];
|
|
||||||
DatagramPacket datagrampacket = new DatagramPacket(abyte0, abyte0.length);
|
|
||||||
datagramsocket.receive(datagrampacket);
|
|
||||||
System.out.println(" ok ");
|
|
||||||
ReqFile reqfile = new ReqFile(abyte0);
|
|
||||||
if(!((Req) (reqfile)).legal)
|
|
||||||
{
|
|
||||||
System.out.println("Can't download module " + s);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
module.Size = reqfile.Size;
|
|
||||||
module.Header = reqfile.Header;
|
|
||||||
module.Data = new byte[module.Size];
|
|
||||||
Module module1 = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
module1 = new Module(s);
|
|
||||||
}
|
|
||||||
catch(Exception exception3)
|
|
||||||
{
|
|
||||||
module1 = null;
|
|
||||||
}
|
|
||||||
if(module1 != null && module1.compareHeader(module))
|
|
||||||
{
|
|
||||||
byte abyte1[] = Cmd_Abort("");
|
|
||||||
datagramsocket.send(new DatagramPacket(abyte1, abyte1.length, inetaddress, i));
|
|
||||||
System.out.println(s + " is already the newest version.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
System.out.print("downloading data");
|
|
||||||
int k = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
byte abyte2[] = Cmd_Next(k);
|
|
||||||
datagramsocket.send(new DatagramPacket(abyte2, abyte2.length, inetaddress, i));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(50L);
|
|
||||||
}
|
|
||||||
catch(Exception exception4) { }
|
|
||||||
abyte2 = new byte[16534];
|
|
||||||
DatagramPacket datagrampacket1 = new DatagramPacket(abyte2, abyte2.length);
|
|
||||||
|
|
||||||
try {
|
|
||||||
datagramsocket.receive(datagrampacket1);
|
|
||||||
} catch (InterruptedIOException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReqBlock reqblock = new ReqBlock(abyte2);
|
|
||||||
if(!((Req) (reqblock)).legal)
|
|
||||||
{
|
|
||||||
if(!"FINISH".equals(((Req) (reqblock)).Cmd))
|
|
||||||
throw new Exception("Protocol violation");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.arraycopy(reqblock.Data, 0, module.Data, k, reqblock.Size);
|
|
||||||
k += reqblock.Size;
|
|
||||||
System.out.print(".");
|
|
||||||
} while(true);
|
|
||||||
if(k != module.Size)
|
|
||||||
{
|
|
||||||
throw new Exception("File size mismatch");
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
System.out.println("done");
|
|
||||||
Module.decode(module.Data, j);
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
if(datagramsocket != null)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
datagramsocket.close();
|
|
||||||
}
|
|
||||||
catch(Exception exception1) { }
|
|
||||||
System.out.println("Can't download module " + s);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void LoadModule(String s, int i, String s1, boolean flag)
|
|
||||||
{
|
|
||||||
DatagramSocket datagramsocket = null;
|
|
||||||
Object obj = null;
|
|
||||||
System.out.println("Loading from " + s + ":" + i);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
datagramsocket = new DatagramSocket();
|
|
||||||
datagramsocket.setSoTimeout(10000);
|
|
||||||
InetAddress inetaddress = InetAddress.getByName(s);
|
|
||||||
Module module = LoadModule(datagramsocket, inetaddress, i, s1, flag);
|
|
||||||
if(module != null)
|
|
||||||
module.write();
|
|
||||||
}
|
|
||||||
catch(Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
if(datagramsocket != null)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
datagramsocket.close();
|
|
||||||
}
|
|
||||||
catch(Exception exception2) { }
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
datagramsocket.close();
|
|
||||||
}
|
|
||||||
catch(Exception exception1) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte[] sendReq(byte abyte0[], int i, String s, int j)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
DatagramSocket datagramsocket = new DatagramSocket(i);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
datagramsocket.setSoTimeout(30000);
|
|
||||||
datagramsocket.send(new DatagramPacket(abyte0, abyte0.length, InetAddress.getByName(s), j));
|
|
||||||
byte abyte1[] = new byte[512];
|
|
||||||
DatagramPacket datagrampacket = new DatagramPacket(abyte1, abyte1.length);
|
|
||||||
datagramsocket.receive(datagrampacket);
|
|
||||||
byte abyte2[] = new byte[datagrampacket.getLength()];
|
|
||||||
System.arraycopy(datagrampacket.getData(), 0, abyte2, 0, datagrampacket.getLength());
|
|
||||||
datagramsocket.close();
|
|
||||||
return abyte2;
|
|
||||||
}
|
|
||||||
catch(Exception exception)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
datagramsocket.close();
|
|
||||||
}
|
|
||||||
catch(Exception exception1) { }
|
|
||||||
throw exception;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String args[])
|
|
||||||
{
|
|
||||||
System.out.println("Half-Life secure server emulator by Tomas Janousek <tomi@nomi.cz>");
|
|
||||||
System.out.println("Based on Secure server emulator v1.3.2 by Shtirlits boris@uchcom.botik.ru");
|
|
||||||
System.out.println();
|
|
||||||
String s = "half-life.speakeasy-nyc.hlauth.net";
|
|
||||||
int i = 27012;
|
|
||||||
char c = '\u6984';
|
|
||||||
String s1 = "";
|
|
||||||
if(args.length > 0)
|
|
||||||
s1 = args[0];
|
|
||||||
if("help".equalsIgnoreCase(s1))
|
|
||||||
{
|
|
||||||
System.out.println(" ");
|
|
||||||
System.out.println("usage:");
|
|
||||||
System.out.println(" ");
|
|
||||||
System.out.println(" to start server: java -jar vac.jar [port]");
|
|
||||||
System.out.println(" ");
|
|
||||||
System.out.println(" to load module: java -jar vac.jar load filename [host port]");
|
|
||||||
System.out.println(" ");
|
|
||||||
System.out.println(" by default download from half-life.speakeasy-nyc.hlauth.net:27012");
|
|
||||||
System.out.println(" ");
|
|
||||||
System.out.println(" files:");
|
|
||||||
System.out.println(" CStrike: DoD:");
|
|
||||||
System.out.println(" cstrike/ModuleC.dll dod/ModuleC.dll");
|
|
||||||
System.out.println(" cstrike/ModuleS.dll dod/ModuleS.dll");
|
|
||||||
System.out.println(" cstrike/ModuleS_i386.so dod/ModuleS_i386.so");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if("load".equalsIgnoreCase(s1))
|
|
||||||
{
|
|
||||||
if(args.length < 2)
|
|
||||||
{
|
|
||||||
System.out.println("File name to download not specified.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(args.length == 4)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
i = Integer.parseInt(args[3]);
|
|
||||||
s = args[2];
|
|
||||||
}
|
|
||||||
catch(Exception exception)
|
|
||||||
{
|
|
||||||
i = 27012;
|
|
||||||
s = "half-life.speakeasy-nyc.hlauth.net";
|
|
||||||
}
|
|
||||||
LoadModule(s, i, args[1], false);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
int j;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
j = Integer.parseInt(s1);
|
|
||||||
}
|
|
||||||
catch(Exception exception1)
|
|
||||||
{
|
|
||||||
j = 27012;
|
|
||||||
}
|
|
||||||
(new vacemu()).serv(j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static String TestModuleDir = "\\private\\vactest";
|
|
||||||
static SimpleDateFormat DF = new SimpleDateFormat("dd.MM.yy HH:mm:ss ");
|
|
||||||
byte buf[];
|
|
||||||
DatagramSocket S;
|
|
||||||
DatagramPacket P;
|
|
||||||
Hashtable Connections;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
All segments that break out of curses (usually to read in from the console) cause odd behaviors. For example, in windows the console window scrolls down to output and must be manually scrolled back up by the user, making it difficult to realize you're back at the menu in curses mode. This for some reason rectifies itself if you go back to the main menu, but I couldn't replicate that effect anywhere else. Some curses quirk I just don't know about, I guess.
|
|
||||||
|
|
||||||
m2ms suffer from nulls in ports and IPs screwing the tokenizing. May be present elsewhere. fix when using memcmp: either force all calls to GetKeyPairValue to use packetbuffer and co, or add in size key. 'Temp' fix: update pointer in z packets to just beyond IP/port.
|
|
||||||
|
|
||||||
Transistor claims M2Ms only work one way. Haven't been able to replicate issue yet.
|
|
||||||
|
|
||||||
Server counter sometimes goes noticeably askew. No effect on logic.
|
|
||||||
|
|
||||||
Endian woes in master server structs. We should store in network order.
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
09.12.2008: If you ban an IP, that IP should no longer be able to send you heartbeats, effectively blocking that server from being listed. Unfortunately, M2Ms weren't checked, so a blocked server could still be listed if M2Ms are both accepted and a server that sends M2Ms hasn't blocked the same server you have. Whelp, I plugged that hole. Yay.
|
|
||||||
|
|
||||||
02:17: If someone sends the packet an unrecognized type, it no longer replies. Before, there was a very nasty back-and-forth transmission between the master and a game server if the master was banned on the game server, for some reason. Whoops.
|
|
||||||
|
|
||||||
12:27: Untested changes. M2Ms have the option to be sent on all heartbeats, and Ben's protests over the incorrect MOD server query should be pacified.
|
|
||||||
|
|
||||||
12:01: Actually TESTED the previous update's code, and fixed it. Also polished the turd a bit more.
|
|
||||||
|
|
||||||
11.31: Revisited code after working on HL engien for a while. Lots of little internal formatting changes, biggest functionality change is the addition of MOD server packets, and a class to handle mods. Untested and incomplete though--it's not polished, but it should work.
|
|
||||||
|
|
||||||
06.03: Updated a fair bit of printable text, changed the version system to use the __DATE__ and __TIME__ preprocessor thingies. Also removed all the commandline parsing crap and replaced with with a library called 'Options'.
|
|
||||||
It looks soooo much neater.
|
|
||||||
|
|
||||||
05.18: Fixed bug (misconception) about getting the local addresses.
|
|
||||||
Fixed bug when deleting bans. It was one character.
|
|
||||||
Forced 0 and -1 addresses to be banned by default (since they're also 'bad string' values)
|
|
||||||
Added unroutable classes by default
|
|
||||||
Developed concerns over accuracy of banning; rejected connections now logged.
|
|
||||||
No longer floods console over ENETRESET
|
|
||||||
Now records number of failed transmissions (ENETRESET)
|
|
||||||
|
|
||||||
v0.75: Menu is done. Well more-or-less; it's workable, if not all that user friendly. You SHOULD use config files instead of the menu anyway, but the option is there and some of it has even been tested. The config file stuff is also done, and while I *could* let you define which files to load from, right now they're static. That's easily changed if you absolutely HAVE to load from your favorite file name. Oh, and I made some much needed changes to the Won2 network lists. Near as I can tell I just forgot to add in a few impotant things. Fixed. It should now be very difficult to send yourself packets, and dummy master servers shouldn't do bad things.
|
|
||||||
03.30: Fixed small bug that caused adding masters to hang horribly. Also finally got the libaries to compile smoothly on linux and found out about an obscure curses 'feature' that acts differently in unix than windows (fixed). And lastly, fixed the thing not correctly sending MSMs and giving errors.04.10: finally hacked together workaround, uh, I mean fixed, everything related to m2ms. Really. This time I think I got it. New bug regarding filter requests found and finally fixed.
|
|
||||||
|
|
||||||
v0.71b: Began merging classes 'stats' and 'input'. Lots of messy curses windows created, destroyed. As of right now, parts of the menu work, and the internals are manageable.
|
|
||||||
|
|
||||||
v0.71a: Added a few #defines and got it to compile on a unix box. Hah! You must alter one line of
|
|
||||||
port.h in order to specify your system though.
|
|
||||||
-lncurses -pthreads
|
|
||||||
03.02: Retooled 'v' packets. Looks better, probably more stable, base functionality hasn't really changed.
|
|
||||||
Added in filtering. Untested.
|
|
||||||
Retooled '0' and 'z' packets when adding servers. Code is possibly a little bit slower, but it is better organized which will make adding stats easier.
|
|
||||||
03.04: Those zeros on the main window now go up and down when servers chime in :)
|
|
||||||
03.07: I know I fixed that optimization bug in 'stats.cc'... How did I lose that update? Re-fixed.
|
|
||||||
|
|
||||||
v0.70a:
|
|
||||||
Started curses interface, began finding all printfs and arranging windows. Made some small code changes I missed the first time around to wonnetwk class; bug has mysteriously vanished...
|
|
||||||
|
|
||||||
v0.65 rc3:
|
|
||||||
Fixed Remake_w_replypacket(); now works, problem was just a stupid mistaek.
|
|
||||||
|
|
||||||
v0.65 rc2:
|
|
||||||
Spent 6 months working on project, finally crossed 'start logging changes' from list
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
There are three threads.
|
|
||||||
|
|
||||||
|
|
||||||
Thread 1 blocks until the user hits a key, and then acts upon the input.
|
|
||||||
|
|
||||||
Thread 2 handles the statistics output, sleeping for one second before updating the display. It does nothing necessary, and is effectively 'suspended' while the menu is in use.
|
|
||||||
|
|
||||||
Thread 3 blocks until a packet is received. Thread 3 is also responsible for spawning the threads that time out servers and handle DNS changes.
|
|
||||||
One thing that is important to note is that thread 3's management CANNOT OCCUR unless packets are being processed. This was intentional, but can impede debugging operations if it is not known.
|
|
||||||
Thread 3 does NOT spawn a new thread for each packet received; it handles them all one at a time. This could prevent it from reaching whatever maximum throughput the host computer is capable of, but this maximum would be very hard to achieve. Still, it's a possible upgrade.
|
|
||||||
|
|
||||||
|
|
||||||
If the user decides they want a outputless run, threads are ignored and the program simply jumps to the function thread 3 starts with. The program will only terminate when given the kill signal. At present jumping into that mode involves undoing curses and a lot of other unnecessary configuration. The proper way to do it would most likly be to put all file and command line parsing in the IO constructor and have it return or throw or something to indicate we want no output, and then be a completely separate block of code. Hindsight and all that; that would be a bit of a restructuring that I just don't feel like doing.
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_project_file>
|
|
||||||
<FileVersion major="1" minor="6" />
|
|
||||||
<Project>
|
|
||||||
<Option title="Mod server" />
|
|
||||||
<Option pch_mode="2" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Build>
|
|
||||||
<Target title="Release">
|
|
||||||
<Option output="bin\Release\Mod server" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option object_output="obj\Release\" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-O2" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-s" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
</Build>
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-fexceptions" />
|
|
||||||
</Compiler>
|
|
||||||
<Unit filename="ModList.cc" />
|
|
||||||
<Unit filename="ModList.h" />
|
|
||||||
<Unit filename="WONnetwk.cc" />
|
|
||||||
<Unit filename="WONnetwk.h" />
|
|
||||||
<Unit filename="banlist.cc" />
|
|
||||||
<Unit filename="banlist.h" />
|
|
||||||
<Unit filename="chalnum.cc" />
|
|
||||||
<Unit filename="chalnum.h" />
|
|
||||||
<Unit filename="externs.h" />
|
|
||||||
<Unit filename="input.cc" />
|
|
||||||
<Unit filename="input.h" />
|
|
||||||
<Unit filename="main.cc" />
|
|
||||||
<Unit filename="packetry.cc" />
|
|
||||||
<Unit filename="packetry.h" />
|
|
||||||
<Unit filename="pkt_IN.cc" />
|
|
||||||
<Unit filename="pkt_OUT.cc" />
|
|
||||||
<Unit filename="port.h" />
|
|
||||||
<Extensions>
|
|
||||||
<code_completion />
|
|
||||||
<envvars />
|
|
||||||
<debugger />
|
|
||||||
</Extensions>
|
|
||||||
</Project>
|
|
||||||
</CodeBlocks_project_file>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_layout_file>
|
|
||||||
<ActiveTarget name="Release" />
|
|
||||||
<File name="ModList.cc" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="4393" topLine="53" />
|
|
||||||
</File>
|
|
||||||
<File name="ModList.h" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="768" topLine="12" />
|
|
||||||
</File>
|
|
||||||
<File name="WONnetwk.cc" open="0" top="0" tabpos="3">
|
|
||||||
<Cursor position="2596" topLine="74" />
|
|
||||||
</File>
|
|
||||||
<File name="WONnetwk.h" open="0" top="0" tabpos="4">
|
|
||||||
<Cursor position="485" topLine="14" />
|
|
||||||
</File>
|
|
||||||
<File name="banlist.cc" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="2365" topLine="75" />
|
|
||||||
</File>
|
|
||||||
<File name="banlist.h" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="574" topLine="8" />
|
|
||||||
</File>
|
|
||||||
<File name="chalnum.cc" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="424" topLine="0" />
|
|
||||||
</File>
|
|
||||||
<File name="externs.h" open="0" top="0" tabpos="6">
|
|
||||||
<Cursor position="623" topLine="0" />
|
|
||||||
</File>
|
|
||||||
<File name="input.cc" open="0" top="0" tabpos="2">
|
|
||||||
<Cursor position="1109" topLine="30" />
|
|
||||||
</File>
|
|
||||||
<File name="input.h" open="0" top="0" tabpos="5">
|
|
||||||
<Cursor position="746" topLine="11" />
|
|
||||||
</File>
|
|
||||||
<File name="main.cc" open="0" top="0" tabpos="1">
|
|
||||||
<Cursor position="817" topLine="3" />
|
|
||||||
</File>
|
|
||||||
<File name="packetry.cc" open="0" top="0" tabpos="7">
|
|
||||||
<Cursor position="1405" topLine="42" />
|
|
||||||
</File>
|
|
||||||
<File name="packetry.h" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="1014" topLine="0" />
|
|
||||||
</File>
|
|
||||||
<File name="pkt_IN.cc" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="23" topLine="0" />
|
|
||||||
</File>
|
|
||||||
<File name="pkt_OUT.cc" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="2168" topLine="51" />
|
|
||||||
</File>
|
|
||||||
<File name="port.h" open="0" top="0" tabpos="0">
|
|
||||||
<Cursor position="870" topLine="1" />
|
|
||||||
</File>
|
|
||||||
</CodeBlocks_layout_file>
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_project_file>
|
|
||||||
<FileVersion major="1" minor="6" />
|
|
||||||
<Project>
|
|
||||||
<Option title="Mod server" />
|
|
||||||
<Option pch_mode="2" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Build>
|
|
||||||
<Target title="Release">
|
|
||||||
<Option output="bin\Release\Mod server" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option object_output="obj\Release\" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-O2" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-s" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
</Build>
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-Wall" />
|
|
||||||
</Compiler>
|
|
||||||
<Unit filename="main.c">
|
|
||||||
<Option compilerVar="CC" />
|
|
||||||
</Unit>
|
|
||||||
<Extensions>
|
|
||||||
<code_completion />
|
|
||||||
<envvars />
|
|
||||||
<debugger />
|
|
||||||
</Extensions>
|
|
||||||
</Project>
|
|
||||||
</CodeBlocks_project_file>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_layout_file>
|
|
||||||
<ActiveTarget name="Release" />
|
|
||||||
</CodeBlocks_layout_file>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
printf("Hello world!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,284 +0,0 @@
|
|||||||
#include "ModList.h"
|
|
||||||
|
|
||||||
/* Class notes:
|
|
||||||
//
|
|
||||||
// This class is more compact than others. The basic idea is just to keep
|
|
||||||
// track of people's mods.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*** Constructor/Destructor and related ***/
|
|
||||||
|
|
||||||
/* DESCRIPTION: All of the class management stuff
|
|
||||||
//
|
|
||||||
// A little differen from how I normally describe things...
|
|
||||||
// The constructor nulls the lists, the destructor deallocates them.
|
|
||||||
// The three deallocation functions are all identical save for the name
|
|
||||||
// of the list they work off of. Also can be used to force a refresh.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
ModList::ModList() {
|
|
||||||
|
|
||||||
/* Thread locks */
|
|
||||||
pthread_mutexattr_init(&ModList_linklist_lockAttribute);
|
|
||||||
pthread_mutexattr_settype(&ModList_linklist_lockAttribute, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
|
|
||||||
pthread_mutex_init(&ModList_linklist_lock, &ModList_linklist_lockAttribute);
|
|
||||||
|
|
||||||
CurrentMods = NULL;
|
|
||||||
}
|
|
||||||
ModList::~ModList() {
|
|
||||||
|
|
||||||
DeallocateMods();
|
|
||||||
|
|
||||||
pthread_mutexattr_destroy(&ModList_linklist_lockAttribute);
|
|
||||||
pthread_mutex_destroy(&ModList_linklist_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Standard freeing. Remember--server entries have POINTERS to here. Don't
|
|
||||||
//wipe one without wiping the other.
|
|
||||||
void ModList::DeallocateMods() {
|
|
||||||
|
|
||||||
ActiveMods_t * ptr;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&ModList_linklist_lock);
|
|
||||||
|
|
||||||
while(CurrentMods != NULL) {
|
|
||||||
ptr = CurrentMods;
|
|
||||||
CurrentMods = CurrentMods->next;
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: ChangeMod
|
|
||||||
//
|
|
||||||
// There are two arguments (and either one can be NULL).
|
|
||||||
// "NewModDirectory" indicates that a server is running the following mod.
|
|
||||||
//
|
|
||||||
// "CurrentModPointer" indicates that a server WAS running the mod it points
|
|
||||||
// to during the last update.
|
|
||||||
//
|
|
||||||
// Usually they both refer to the same mod--the server just wants to update
|
|
||||||
// how many people are playing it.
|
|
||||||
//
|
|
||||||
// If a server is being removed, NewModDirectory would be null. If a server is
|
|
||||||
// being added for the first time, CurrentModPointer will be null.
|
|
||||||
//
|
|
||||||
// If a server is changing its mod (hard, but possible), they'll be different.
|
|
||||||
//
|
|
||||||
// Either way, we add and decrement as needed. We MAY return NULL in some
|
|
||||||
// error cases. The wisest move would probably be for any heartbeat
|
|
||||||
// that results in such a case to be terminated, but I'm reasonably certain
|
|
||||||
// a NULL pointer won't affect the stability of the program.
|
|
||||||
//
|
|
||||||
// note: NewModDir being "" would simplify strcmp checks. Consider for future.
|
|
||||||
*/
|
|
||||||
ActiveMods_t * ModList::ChangeMod(const char *NewModDirectory, ActiveMods_t * CurrentModPointer, const int OldPlayerCount, const int NewPlayerCount) {
|
|
||||||
|
|
||||||
ActiveMods_t * ptr, * ptr2;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&ModList_linklist_lock);
|
|
||||||
|
|
||||||
//We should probably start with removal.
|
|
||||||
if(CurrentModPointer != NULL) {
|
|
||||||
|
|
||||||
//Are we actually changing mods?
|
|
||||||
if(NewModDirectory != NULL && strncasecmp(CurrentModPointer->ModName, NewModDirectory, 64) == 0) {
|
|
||||||
|
|
||||||
//Just changing the number of players.
|
|
||||||
CurrentModPointer->PlayerCount += (NewPlayerCount - OldPlayerCount);
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
return(CurrentModPointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Otherwise we're changing the mod. Or (more likely) going offline.
|
|
||||||
CurrentModPointer->PlayerCount -= OldPlayerCount;
|
|
||||||
CurrentModPointer->ServerCount--;
|
|
||||||
|
|
||||||
//And remove the old mod pointer if that's the last one.
|
|
||||||
if(CurrentModPointer->ServerCount == 0) {
|
|
||||||
|
|
||||||
UnlinkModNode(CurrentModPointer);
|
|
||||||
free(CurrentModPointer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NewModDirectory != NULL) {
|
|
||||||
|
|
||||||
if(strcmp(NewModDirectory, "start-of-list") == 0) { //nice try
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
//That was easy. Now to see if any nodes already have this mod.
|
|
||||||
ptr = CurrentMods;
|
|
||||||
ptr2 = NULL;
|
|
||||||
while(ptr != NULL) {
|
|
||||||
|
|
||||||
i = strncasecmp(ptr->ModName, NewModDirectory, 64);
|
|
||||||
|
|
||||||
if(i == 0) { //match
|
|
||||||
|
|
||||||
ptr->ServerCount++;
|
|
||||||
ptr->PlayerCount += NewPlayerCount;
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
return(ptr);
|
|
||||||
}
|
|
||||||
if(i > 0) { break; }
|
|
||||||
|
|
||||||
ptr2 = ptr;
|
|
||||||
ptr = ptr->next;
|
|
||||||
|
|
||||||
}
|
|
||||||
//We didn't find a matching node. We will have to make our own.
|
|
||||||
//We're going to hang on to ptr2. That var holds the node that
|
|
||||||
//would precede our newly malloc'd node.
|
|
||||||
|
|
||||||
ptr = (ActiveMods_t *)malloc(sizeof(ActiveMods_t));
|
|
||||||
if(ptr == NULL) {
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
strncpy(ptr->ModName, NewModDirectory, 63);
|
|
||||||
ptr->ModName[63] = '\0';
|
|
||||||
|
|
||||||
ptr->ServerCount = 1;
|
|
||||||
ptr->PlayerCount = NewPlayerCount;
|
|
||||||
//And now to link.
|
|
||||||
|
|
||||||
if(ptr2 == NULL) { //First node.
|
|
||||||
|
|
||||||
ptr->previous = NULL;
|
|
||||||
ptr->next = CurrentMods;
|
|
||||||
if(CurrentMods != NULL) {
|
|
||||||
CurrentMods->previous = ptr;
|
|
||||||
}
|
|
||||||
CurrentMods = ptr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptr->previous = ptr2;
|
|
||||||
ptr->next = ptr2->next;
|
|
||||||
if(ptr2->next != NULL) {
|
|
||||||
ptr2->next->previous = ptr;
|
|
||||||
}
|
|
||||||
ptr2->next = ptr;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
return(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: FillPacketBufferWithMods
|
|
||||||
//
|
|
||||||
// It's assumed that the buffer is an outgoing packet. Cycle through the mod
|
|
||||||
// list and add as needed.
|
|
||||||
//
|
|
||||||
// Notes of interest: "start-of-list" is a reserved value, and
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
unsigned long int ModList::FillPacketBufferWithMods(const char * StartMod, char * buffer, const unsigned int SizeOfBuffer) {
|
|
||||||
|
|
||||||
unsigned int packetlen = 0;
|
|
||||||
ActiveMods_t * ptr;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&ModList_linklist_lock);
|
|
||||||
|
|
||||||
ptr = CurrentMods;
|
|
||||||
|
|
||||||
if(strcmp(StartMod, "start-of-list") != 0) {
|
|
||||||
|
|
||||||
while(ptr != NULL && strncasecmp(ptr->ModName, StartMod, 63) != 0) {
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while(ptr != NULL) {
|
|
||||||
|
|
||||||
if(packetlen >= SizeOfBuffer - (36 + strlen(ptr->ModName))) {
|
|
||||||
//not enough room. 36 = sizeof("more-in-list") + 3 nulls + max length
|
|
||||||
//of the two ints. When porting to 64 bit, that won't fly.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
packetlen += 1 + sprintf(buffer + packetlen, "%s", ptr->ModName);
|
|
||||||
packetlen += 1 + sprintf(buffer + packetlen, "%u", ptr->ServerCount);
|
|
||||||
packetlen += 1 + sprintf(buffer + packetlen, "%u", ptr->PlayerCount);
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ptr == NULL) { //finished successfully
|
|
||||||
memcpy(buffer + packetlen, "end-of-list", sizeof("end-of-list"));
|
|
||||||
packetlen += sizeof("end-of-list");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
memcpy(buffer + packetlen, "more-in-list", sizeof("more-in-list"));
|
|
||||||
packetlen += sizeof("more-in-list");
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
|
|
||||||
return(packetlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//This function is actually more of an example. Parts of it are used elsewhere.
|
|
||||||
void ModList::AddModNode(ActiveMods_t * modToBeAdded) {
|
|
||||||
|
|
||||||
//list is in alphabetical order
|
|
||||||
ActiveMods_t * ptr;
|
|
||||||
|
|
||||||
//Condition 1: we have no nodes
|
|
||||||
if(CurrentMods == NULL) {
|
|
||||||
CurrentMods = modToBeAdded;
|
|
||||||
CurrentMods->previous = NULL; //This node is now #1
|
|
||||||
CurrentMods->next = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = CurrentMods;
|
|
||||||
|
|
||||||
//Condition 2: We need to change our first node
|
|
||||||
if(strncasecmp(ptr->ModName, modToBeAdded->ModName, 64) > 0) {
|
|
||||||
|
|
||||||
CurrentMods = modToBeAdded;
|
|
||||||
CurrentMods->previous = NULL;
|
|
||||||
CurrentMods->next = ptr;
|
|
||||||
ptr->previous = CurrentMods;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
while(ptr->next->ModName != NULL && strncasecmp(ptr->next->ModName, modToBeAdded->ModName, 64) < 0) {
|
|
||||||
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
//At this stage ptr is the node that should PRECEDE our passed node.
|
|
||||||
modToBeAdded->previous = ptr;
|
|
||||||
modToBeAdded->next = ptr->next;
|
|
||||||
|
|
||||||
//Condition 3: This is going to be our last node
|
|
||||||
if(ptr->next != NULL) {
|
|
||||||
ptr->next->previous = modToBeAdded;
|
|
||||||
}
|
|
||||||
ptr->next = modToBeAdded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void ModList::UnlinkModNode(ActiveMods_t * modToBeDeleted) {
|
|
||||||
|
|
||||||
if(modToBeDeleted->previous == NULL) { //This must be the first node
|
|
||||||
CurrentMods = modToBeDeleted->next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
modToBeDeleted->previous->next = modToBeDeleted->next;
|
|
||||||
}
|
|
||||||
if(modToBeDeleted->next != NULL) {
|
|
||||||
modToBeDeleted->next->previous = modToBeDeleted->previous; //There we go; unlinked.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/* This class deals with the management of mods for the mod server.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__WON2_MOD_LIST__H_
|
|
||||||
#define __MASTER__SERVER__WON2_MOD_LIST__H_
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include "port.h"
|
|
||||||
#include "externs.h"
|
|
||||||
#include "packetry.h"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*** Structs ***/
|
|
||||||
typedef struct ActiveMods_s {
|
|
||||||
|
|
||||||
struct ActiveMods_s *next, *previous;
|
|
||||||
char ModName[64];
|
|
||||||
|
|
||||||
} ActiveMods_t;
|
|
||||||
|
|
||||||
|
|
||||||
/*** The class ***/
|
|
||||||
typedef class ModList {
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/* lists */
|
|
||||||
ActiveMods_t * CurrentMods;
|
|
||||||
|
|
||||||
void AddModNode(ActiveMods_t *);
|
|
||||||
void UnlinkModNode(ActiveMods_t *);
|
|
||||||
void DeallocateMods();
|
|
||||||
|
|
||||||
/* Thread locks */
|
|
||||||
pthread_mutex_t ModList_linklist_lock;
|
|
||||||
pthread_mutexattr_t ModList_linklist_lockAttribute;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ActiveMods_t * ChangeMod(const char *, ActiveMods_t *, const int, const int);
|
|
||||||
unsigned long int FillPacketBufferWithMods(const char *, char *, const unsigned int);
|
|
||||||
ModList();
|
|
||||||
~ModList();
|
|
||||||
|
|
||||||
} ModList_c;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,639 +0,0 @@
|
|||||||
#include "SrvrNtwk.h"
|
|
||||||
|
|
||||||
/*** Threads ***/
|
|
||||||
|
|
||||||
|
|
||||||
void ServerList::ServerTimeouts(void *a) {
|
|
||||||
|
|
||||||
class ServerList* pthis = (class ServerList*)a;
|
|
||||||
unsigned int UnixTime = (ptrIO->CheckCurrentTime()) - pthis->ServerTimeoutValueInSeconds;
|
|
||||||
|
|
||||||
ptrIO->OutputFileData(4, "Timeout thread running");
|
|
||||||
pthread_mutex_lock(&(pthis->Serverlist_lock));
|
|
||||||
|
|
||||||
HLserver_t * ptr = pthis->BeginningOfServerlist;
|
|
||||||
HLserver_t * ptr2;
|
|
||||||
while(ptr != NULL) {
|
|
||||||
ptr2 = ptr->left;
|
|
||||||
|
|
||||||
if(ptr->last_heartbeat < UnixTime) {
|
|
||||||
pthis->DeleteNode(ptr);
|
|
||||||
}
|
|
||||||
ptr = ptr2;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&(pthis->Serverlist_lock));
|
|
||||||
pthis->AreServersTimingOut = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** Constructor/Destructor and related ***/
|
|
||||||
|
|
||||||
/* DESCRIPTION: All of the class management stuff
|
|
||||||
//
|
|
||||||
// A little differen from how I normally describe things...
|
|
||||||
// The constructor nulls the lists, the destructor deallocates them.
|
|
||||||
// The three deallocation functions are all identical save for the name
|
|
||||||
// of the list they work off of. Also can be used to force a refresh.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
ServerList::ServerList() {
|
|
||||||
|
|
||||||
/* Thread locks */
|
|
||||||
pthread_mutexattr_init(&Serverlist_lockAttribute);
|
|
||||||
pthread_mutexattr_settype(&Serverlist_lockAttribute, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
pthread_mutex_init(&Serverlist_lock, &Serverlist_lockAttribute);
|
|
||||||
|
|
||||||
|
|
||||||
BeginningOfServerlist = NULL;
|
|
||||||
FirstFreeNode = NULL;
|
|
||||||
ReserveNodes = 0;
|
|
||||||
ServerTimeoutValueInSeconds = 600;
|
|
||||||
AreServersTimingOut = 0;
|
|
||||||
HaveServersEverTimedOut = 0;
|
|
||||||
orig_ThreadServerTimeouts = (lpfn_ServerTimeouts)ServerTimeouts;
|
|
||||||
|
|
||||||
}
|
|
||||||
ServerList::~ServerList() {
|
|
||||||
|
|
||||||
if(HaveServersEverTimedOut) { pthread_join(ThreadServerTimeouts, NULL); }
|
|
||||||
DeallocateServers();
|
|
||||||
DeallocateReserveNodes();
|
|
||||||
|
|
||||||
pthread_mutexattr_destroy(&Serverlist_lockAttribute);
|
|
||||||
pthread_mutex_destroy(&Serverlist_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* C/D functions */
|
|
||||||
|
|
||||||
/* DESCRIPTION: DeallocateServers
|
|
||||||
//
|
|
||||||
// If we are wiping EVERY node, there's no point in pooling memory pages with
|
|
||||||
// FreeUnlinkedNode. We just go and free() it all in one function.
|
|
||||||
// Intended as part of the program termination, but could be used in a reset.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void ServerList::DeallocateServers() {
|
|
||||||
|
|
||||||
HLserver_t * ptr;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
while(BeginningOfServerlist != NULL) {
|
|
||||||
ptr = BeginningOfServerlist;
|
|
||||||
BeginningOfServerlist = BeginningOfServerlist->left;
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: DeallocateReserveNodes
|
|
||||||
//
|
|
||||||
// Eventually the program ends and all the memory it had needs to be returned.
|
|
||||||
// That time is now, so we go through out free structure pool and free() each
|
|
||||||
// one. That's it.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void ServerList::DeallocateReserveNodes() {
|
|
||||||
|
|
||||||
HLserver_t* ptr;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
while(FirstFreeNode != NULL) {
|
|
||||||
ptr = FirstFreeNode;
|
|
||||||
FirstFreeNode = FirstFreeNode->left;
|
|
||||||
free(ptr);
|
|
||||||
ReserveNodes--;
|
|
||||||
}
|
|
||||||
if(ReserveNodes != 0) { ptrIO->OutputWindowPrintf(2, "PSA: ReserveNodes doesn't equal zero and it should."); }
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerList::ChangeServerTimeoutValue(unsigned int x) {
|
|
||||||
if(x > 60) {
|
|
||||||
ServerTimeoutValueInSeconds = x; //OO makes EVERYTHING fun...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Basic malloc and free */
|
|
||||||
|
|
||||||
/* DESCRIPTION: NewNode
|
|
||||||
//
|
|
||||||
// Easier than I thought it would be. Since server allocation is
|
|
||||||
// constantly giving and receiving bytes, I figured it'd be easier
|
|
||||||
// for everyone involved to not have to malloc left and right.
|
|
||||||
// NewNode handles mallocs; when the free structure pool dips below
|
|
||||||
// 50, it mallocs 400 more, which are stored in a linked list pointed to
|
|
||||||
// by FirstFreeNode. Other than that, it just returns a pointer to one
|
|
||||||
// of the free servers in the list, and moves FirstFreeNode to account
|
|
||||||
// for the change.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
HLserver_t * ServerList::NewNode() {
|
|
||||||
|
|
||||||
HLserver_t * ptr;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
|
|
||||||
//If we have fewer than, say, fifty nodes we might as well allocate 400 more
|
|
||||||
if(ReserveNodes < 50) {
|
|
||||||
for(i=0; i<400; i++) { //400 mallocs; unrolling potential is there
|
|
||||||
ptr = (HLserver_t *)malloc(sizeof(HLserver_t));
|
|
||||||
if(ptr == NULL) { //Crap, we have no memory
|
|
||||||
ptrIO->OutputWindowPrintf(1, "Memory allocation failure. Buy more RAM, cheapskate.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ptr->left = FirstFreeNode;
|
|
||||||
FirstFreeNode = ptr;
|
|
||||||
ReserveNodes++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//regardless of any mallocing, we assume ptr points nowhere we want
|
|
||||||
ptr = FirstFreeNode;
|
|
||||||
if(ptr == NULL) { //crap, we have no memory AND no remaining structures
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
FirstFreeNode = FirstFreeNode->left;
|
|
||||||
ReserveNodes--;
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
|
|
||||||
memset(ptr, 0, sizeof(HLserver_t));
|
|
||||||
return(ptr);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: FreeUnlinkedNode
|
|
||||||
//
|
|
||||||
// Much like NewNode, it handles allocaton and deallocation of
|
|
||||||
// memory. The difference is it adds the passed structure to
|
|
||||||
// the structure pool and, if ReserveNodes gets above, say 750,
|
|
||||||
// it goes through and liquidates 400.
|
|
||||||
// One note of warning: it is impossible to check to see if the
|
|
||||||
// address is valid, and infeasable to see if it has truly been
|
|
||||||
// removed from any trees it was in.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void ServerList::FreeUnlinkedNode(HLserver_t * deadnode) {
|
|
||||||
|
|
||||||
HLserver_t* ptr;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
//No evil input protection; this is especially problematic as any invalid
|
|
||||||
//addresses won't be hit until there are 750 free nodes...
|
|
||||||
|
|
||||||
deadnode->left = FirstFreeNode;
|
|
||||||
FirstFreeNode = deadnode;
|
|
||||||
ReserveNodes++;
|
|
||||||
|
|
||||||
//If we have more than, say, 750 nodes we might as well be nice to the OS
|
|
||||||
if(ReserveNodes > 750) {
|
|
||||||
for(i=0; i<400; i++) {
|
|
||||||
ptr = FirstFreeNode;
|
|
||||||
FirstFreeNode = FirstFreeNode->left;
|
|
||||||
free(ptr);
|
|
||||||
ReserveNodes--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Linked List Adds and Deletes */
|
|
||||||
|
|
||||||
/* DESCRIPTION: AddNode
|
|
||||||
//
|
|
||||||
// Takes an allocated server pointer and links it to our list. Now, there is
|
|
||||||
// a sorting in our list based on the hash number (struct->hashvalue), and it
|
|
||||||
// is assumed that the programmer assigned that before calling this function.
|
|
||||||
// In future I can remove that requirement and have this calculate the hash
|
|
||||||
// manually, but I arbitrarially decided not to.
|
|
||||||
//
|
|
||||||
// Until I need to, it's a boring doubly linked list. There is no effect on
|
|
||||||
// which order hash collisions are added.
|
|
||||||
*/
|
|
||||||
void ServerList::AddNode(HLserver_t * serverToBeAdded) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
HLserver_t * ptr = BeginningOfServerlist;
|
|
||||||
|
|
||||||
|
|
||||||
//Condition 1: we have no nodes
|
|
||||||
if(ptr == NULL) {
|
|
||||||
BeginningOfServerlist = serverToBeAdded;
|
|
||||||
BeginningOfServerlist->previous = NULL; //This node is now #1
|
|
||||||
BeginningOfServerlist->left = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Condition 2: We need to change our first node
|
|
||||||
else if(ptr->hashvalue > serverToBeAdded->hashvalue) {
|
|
||||||
BeginningOfServerlist = serverToBeAdded;
|
|
||||||
BeginningOfServerlist->previous = NULL;
|
|
||||||
BeginningOfServerlist->left = ptr;
|
|
||||||
ptr->previous = BeginningOfServerlist;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
while(ptr->left != NULL && ptr->left->hashvalue < serverToBeAdded->hashvalue) {
|
|
||||||
|
|
||||||
ptr = ptr->left;
|
|
||||||
}
|
|
||||||
|
|
||||||
//At this stage ptr is the node that should PRECEDE our passed node.
|
|
||||||
serverToBeAdded->previous = ptr;
|
|
||||||
serverToBeAdded->left = ptr->left;
|
|
||||||
|
|
||||||
//Condition 3: This is going to be our last node
|
|
||||||
if(ptr->left != NULL) {
|
|
||||||
ptr->left->previous = serverToBeAdded;
|
|
||||||
}
|
|
||||||
ptr->left = serverToBeAdded;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: DeleteNode
|
|
||||||
//
|
|
||||||
// Unlinks one node and adds it to the freenode pool. There's not much to
|
|
||||||
// it right now, but it's written to make converting it to a tree easier.
|
|
||||||
// For now you just pass it the node you want to delete.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void ServerList::DeleteNode(HLserver_t * serverToBeDeleted) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
if(serverToBeDeleted != NULL) { //That's technically delaying the ineviteble if that mistake was made in coding...
|
|
||||||
|
|
||||||
|
|
||||||
//Stats running. We can do it here since we don't need to compare old and new values like when receiving packets.
|
|
||||||
ptrIO->addServers(-1, (serverToBeDeleted->CheckboolIsServerLan()));
|
|
||||||
ptrIO->addPlayers(-(serverToBeDeleted->players), (serverToBeDeleted->CheckboolIsServerLan()));
|
|
||||||
ptrIO->addBots(-(serverToBeDeleted->fakeplayers), (serverToBeDeleted->CheckboolIsServerLan()));
|
|
||||||
|
|
||||||
ptrMods->ChangeMod(NULL, serverToBeDeleted->GameDir, serverToBeDeleted->players, 0);
|
|
||||||
|
|
||||||
if(serverToBeDeleted->previous == NULL) { //This must be the first node
|
|
||||||
BeginningOfServerlist = serverToBeDeleted->left;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
serverToBeDeleted->previous->left = serverToBeDeleted->left;
|
|
||||||
}
|
|
||||||
if(serverToBeDeleted->left != NULL) {
|
|
||||||
serverToBeDeleted->left->previous = serverToBeDeleted->previous; //There we go; unlinked.
|
|
||||||
}
|
|
||||||
|
|
||||||
FreeUnlinkedNode(serverToBeDeleted);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptrIO->OutputWindowPrintf(2, "NULL pointer passed to DeleteNode(). You might want to check that.");
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Functions related to the linked list */
|
|
||||||
|
|
||||||
/* DESCRIPTION: FindNodeBySockaddr
|
|
||||||
//
|
|
||||||
// Calls IP version of function.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
HLserver_t * ServerList::FindNodeBySockaddr(struct sockaddr_in server) {
|
|
||||||
|
|
||||||
return(FindNodeByIP(server.sin_addr.s_addr, server.sin_port));
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: FindNodeByIP
|
|
||||||
//
|
|
||||||
// Compares IPs and hashes until it finds a match. We can use the fact that
|
|
||||||
// it's a sorted linked list to quickly get to the right block, and then
|
|
||||||
// compare until all is well.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
HLserver_t * ServerList::FindNodeByIP(unsigned long int IP, unsigned short int port) {
|
|
||||||
|
|
||||||
unsigned int i = HashServerIP(IP, port); //will be more useful once we have a binary tree
|
|
||||||
HLserver_t * ptr = FindNodeByHash(i);
|
|
||||||
|
|
||||||
//At this point we either have a null pointer or a pointer to the block
|
|
||||||
//our desired server is in.
|
|
||||||
|
|
||||||
while(ptr != NULL && ptr->hashvalue == i) {
|
|
||||||
|
|
||||||
|
|
||||||
if(ptr->IntServerAddress == IP && ptr-> IntServerPort == port) {
|
|
||||||
return(ptr);
|
|
||||||
}
|
|
||||||
ptr = ptr->left;
|
|
||||||
}
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: FindNodeByHash
|
|
||||||
//
|
|
||||||
// Finds the first node with a given hash. Returns null if it isn't found.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
HLserver_t * ServerList::FindNodeByHash(unsigned long int hash) {
|
|
||||||
|
|
||||||
|
|
||||||
HLserver_t * ptr = BeginningOfServerlist;
|
|
||||||
while(ptr != NULL) {
|
|
||||||
|
|
||||||
if(ptr->hashvalue >= hash) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ptr = ptr->left;
|
|
||||||
}
|
|
||||||
if(ptr != NULL && ptr->hashvalue != hash) {
|
|
||||||
ptr = NULL;
|
|
||||||
}
|
|
||||||
return(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: FindNodeofEqualOrLesserHash
|
|
||||||
//
|
|
||||||
// Intended for use when continuing a packet batch request. Will return the
|
|
||||||
// first node that has a matching hash. If no node has a matching hash, returns
|
|
||||||
// the closest match without going over. If all nodes have a greater hash
|
|
||||||
// value (as in the common case of 0 passed), returns the beginning of the list.
|
|
||||||
// And lastly, returns NULL if there are no nodes.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
HLserver_t * ServerList::FindNodeofEqualorLesserHash(unsigned long int hash) {
|
|
||||||
|
|
||||||
HLserver_t* ptr = BeginningOfServerlist;
|
|
||||||
|
|
||||||
if(ptr != NULL) {
|
|
||||||
|
|
||||||
while(ptr->hashvalue < hash && ptr->left != NULL) {
|
|
||||||
ptr = ptr->left;
|
|
||||||
}
|
|
||||||
|
|
||||||
//At this stage: (cases 1, 2, 3, & 5 are set to return)
|
|
||||||
// If we had no nodes, ptr = NULL and control doesn't come here.
|
|
||||||
// If all nodes have hashes > 0, ptr = BeginningOfServerlist.
|
|
||||||
// If the hash is in the middle and exists, ptr = the node.
|
|
||||||
// If the hash is in the middle but DNE, ptr = the node after.
|
|
||||||
// If the hash is too high, ptr = last node.
|
|
||||||
|
|
||||||
if(ptr->hashvalue > hash) //cases 2 & 4
|
|
||||||
if(ptr->previous != NULL) {
|
|
||||||
ptr = ptr->previous;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: HashServer
|
|
||||||
//
|
|
||||||
// Calls IP version of function.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
unsigned int ServerList::HashServer(struct sockaddr_in server) {
|
|
||||||
|
|
||||||
return(HashServerIP(server.sin_addr.s_addr, server.sin_port));
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: HashServerIP
|
|
||||||
//
|
|
||||||
// In order to quickly pick up where we leave off in a server listing, we
|
|
||||||
// need to hash them. We don't need to be quite as picky here though; we
|
|
||||||
// have a good 31 bits to store, and repeated hash collisions--MANY repeated
|
|
||||||
// hash collisions--won't do anything except possibly omit a server. I
|
|
||||||
// would like to keep randomness so that people with a 'lucky' IP won't get
|
|
||||||
// an advantage in listing.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
unsigned int ServerList::HashServerIP(unsigned long int IP, unsigned short int port) {
|
|
||||||
|
|
||||||
static int offset = ((rand() | (rand()<<17)) ^ (rand()<<9));
|
|
||||||
|
|
||||||
return(((port ^ (IP<<16) | (IP>>16)) + offset) & 0x7FFFFFFF);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: FillPacketBufferWithIPs
|
|
||||||
//
|
|
||||||
// It's assumed that the buffer is an outgoing packet. This cycles through the
|
|
||||||
// serverlist and adds the whole IP PORT combo until there's not enough room.
|
|
||||||
// Naturally this requires the caller to be careful and not pass a bad
|
|
||||||
// SizeOfBuffer. StartingHash is used to determine where to start in our
|
|
||||||
// linked list, flags are as of yet unused, and this returns the number of
|
|
||||||
// bytes written. StartingHash is also a return value, as it is modified to
|
|
||||||
// become the value of the next node's hash.
|
|
||||||
//
|
|
||||||
// The hash is 31 bits. The 32nd bit is something that should be
|
|
||||||
// processed with another function entirely--do not call this version if the
|
|
||||||
// leftmost hash bit is set in the received packet.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
unsigned long int ServerList::FillPacketBufferWithIPs(unsigned long int* StartingHash, const char* CharBuffer, const unsigned int SizeOfBuffer, const int flags, const char* moddirectory) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
|
|
||||||
unsigned int packetlen = 0;
|
|
||||||
HLserver_t * serverptr = FindNodeofEqualorLesserHash(*StartingHash);
|
|
||||||
|
|
||||||
//To recap FNoEoLH, we have a null if there are no servers, or a server
|
|
||||||
//pointer--probably the beginning of our list.
|
|
||||||
|
|
||||||
while(serverptr != NULL) {
|
|
||||||
|
|
||||||
if(flags) { //Hey, that's one less function call
|
|
||||||
if(!ServerTypeCheck(serverptr, flags, moddirectory)) {
|
|
||||||
serverptr = serverptr->left;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(packetlen >= SizeOfBuffer-6) { break; }
|
|
||||||
|
|
||||||
*(unsigned long int *)(CharBuffer+packetlen) = serverptr->IntServerAddress; //all little endian, not network order
|
|
||||||
packetlen += 4;
|
|
||||||
*(unsigned short int *)(CharBuffer+packetlen) = serverptr->IntServerPort;
|
|
||||||
packetlen += 2;
|
|
||||||
|
|
||||||
serverptr = serverptr->left;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(serverptr == NULL) {
|
|
||||||
*StartingHash = 0x00000000;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
/* The following code that may add 1 to 'position' exists to catch an
|
|
||||||
// infinite loop. If there are 400 or so server hash collisions there's
|
|
||||||
// a chance that we'll give the client the same data over and over again.
|
|
||||||
// This would be hard to abuse (clients would suffer more than us),
|
|
||||||
// and rare by chance (400, WON peaked at like 30000, and the range of
|
|
||||||
// hashes is 2^31). But it's there, and now it's protected.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(*StartingHash == serverptr->hashvalue) {
|
|
||||||
*StartingHash = (serverptr->hashvalue)+1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*StartingHash = (serverptr->hashvalue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
|
|
||||||
return(packetlen);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: ServerTypeCheck
|
|
||||||
//
|
|
||||||
// Clients can ask that we filter our responses by things like game types
|
|
||||||
// and whatnot. Flags are defined; ModName may be empty or a null.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int ServerList::ServerTypeCheck(const HLserver_t * ptr, int flags, const char* ModDir) {
|
|
||||||
|
|
||||||
|
|
||||||
/* From left to right
|
|
||||||
0-------
|
|
||||||
8 1
|
|
||||||
|
|
||||||
Secure 1
|
|
||||||
Proxy 1
|
|
||||||
Linux 1
|
|
||||||
Empty 1
|
|
||||||
Full 1
|
|
||||||
Dedicated 1
|
|
||||||
Mod name specified 1
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(flags & 0x01 == 1) { //mod name specified
|
|
||||||
|
|
||||||
//Inefficient; if we restructured we could just compare pointers.
|
|
||||||
if(strcmp(ModDir, ptr->GameDir->ModName) != 0) { return(0); }
|
|
||||||
}
|
|
||||||
flags = flags>>1;
|
|
||||||
|
|
||||||
if(flags & 0x01 == 1) { //Dedicated 1
|
|
||||||
if(!ptr->CheckboolIsServerDedicated()) { return(0); }
|
|
||||||
}
|
|
||||||
flags = flags>>1;
|
|
||||||
|
|
||||||
if(flags & 0x01 == 1) { //not full
|
|
||||||
if(ptr->players == ptr->maxplayers) { return(0); }
|
|
||||||
}
|
|
||||||
flags = flags>>1;
|
|
||||||
|
|
||||||
if(flags & 0x01 == 1) { //not empty
|
|
||||||
if(ptr->players == 0) { return(0); }
|
|
||||||
}
|
|
||||||
flags = flags>>1;
|
|
||||||
|
|
||||||
if(flags & 0x01 == 1) { //linux
|
|
||||||
if(!ptr->CheckboolIsServerLinux()) { return(0); }
|
|
||||||
}
|
|
||||||
flags = flags>>1;
|
|
||||||
|
|
||||||
if(flags & 0x01 == 1) { //proxy. Still don't know what that does to HL.
|
|
||||||
if(!ptr->CheckboolIsServerProxy()) { return(0); }
|
|
||||||
}
|
|
||||||
flags = flags>>1;
|
|
||||||
|
|
||||||
if(flags & 0x01 == 1) { //secure
|
|
||||||
if(!ptr->CheckboolIsServerSecure()) { return(0); }
|
|
||||||
}
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: SetServerToTimeoutInOneMin
|
|
||||||
//
|
|
||||||
// Servers send special packets when they are going offline. Unfortunately
|
|
||||||
// they are quite spoofable, so if we process them we are opening servers
|
|
||||||
// up for attack. We could also ignore them, and dead servers will go away
|
|
||||||
// after 5 minutes, or we can do this--set the timeout to one minute and go
|
|
||||||
// from there. Servers chime in every minute (in theory), and we can also
|
|
||||||
// ping them. This will do the first half. Returns 1 if there's cause to
|
|
||||||
// send a ping.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int ServerList::SetServerToTimeoutInOneMin(struct sockaddr_in server) {
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
|
|
||||||
HLserver_t * ptr = FindNodeBySockaddr(server);
|
|
||||||
unsigned int UnixTime = (ptrIO->CheckCurrentTime()) - ServerTimeoutValueInSeconds + 60;
|
|
||||||
//UnixTime is set to 1 minute before timeout
|
|
||||||
if(ptr != NULL) {
|
|
||||||
if(ptr->last_heartbeat > UnixTime) { i = 1; }
|
|
||||||
ptr->last_heartbeat = UnixTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: ResetServerTimeout
|
|
||||||
//
|
|
||||||
// If we get an ack from a server, we know it's up. So we update it's
|
|
||||||
// last response time. If we don't have the server listed we ignore
|
|
||||||
// the ack, and return 1 (1 in the PKT_IN fields is a failure).
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int ServerList::ResetServerTimeout(struct sockaddr_in server) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
|
|
||||||
HLserver_t * ptr = FindNodeBySockaddr(server);
|
|
||||||
|
|
||||||
if(ptr != NULL) {
|
|
||||||
ptr->last_heartbeat = ptrIO->CheckCurrentTime();
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: SpawnServerTimeouts
|
|
||||||
//
|
|
||||||
// Spins a thread if one isn't already running (or if it's just about
|
|
||||||
// to end; actually locking the bool shouldn't have any effect, so
|
|
||||||
// that difference is probably splitting hairs). Returns 1 normally
|
|
||||||
// or returns 0 if a thread is already running. May return other
|
|
||||||
// values in future.
|
|
||||||
*/
|
|
||||||
int ServerList::SpawnServerTimeouts() {
|
|
||||||
|
|
||||||
ptrIO->OutputWindowPrintf(2, "Spawning server timeout thread.");
|
|
||||||
|
|
||||||
if(HaveServersEverTimedOut) {
|
|
||||||
pthread_join(ThreadServerTimeouts, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!AreServersTimingOut) {
|
|
||||||
AreServersTimingOut = 1;
|
|
||||||
HaveServersEverTimedOut = 1;
|
|
||||||
pthread_create(&ThreadServerTimeouts, NULL, orig_ThreadServerTimeouts, (void *)this);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
ptrIO->OutputWindowPrintf(2, "ServerTimeouts() aborted. Probably already running.");
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerList::FlushServers() {
|
|
||||||
|
|
||||||
HLserver_t * ptr;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Serverlist_lock);
|
|
||||||
while(BeginningOfServerlist != NULL) {
|
|
||||||
ptr = BeginningOfServerlist;
|
|
||||||
BeginningOfServerlist = BeginningOfServerlist->left;
|
|
||||||
DeleteNode(ptr);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&Serverlist_lock);
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
/* This class deals with the management of servers on the network. This
|
|
||||||
// definitely needs to be a tree or something if we grow too much, but for
|
|
||||||
// now a linked list is acceptable.
|
|
||||||
//
|
|
||||||
// This manages the creation and deletion of nodes, but it is the programmer's
|
|
||||||
// responsibility to ensure the node is properly handled until linked.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__HLSERVER_SERVER_NETWORK_H_
|
|
||||||
#define __MASTER__SERVER__HLSERVER_SERVER_NETWORK_H_
|
|
||||||
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "port.h"
|
|
||||||
#include "externs.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include "ModList.h"
|
|
||||||
|
|
||||||
/*** The server ***/
|
|
||||||
|
|
||||||
typedef struct HLserver_s {
|
|
||||||
|
|
||||||
struct HLserver_s *left, *right, *previous; //tree linkage; only left and previous are being used
|
|
||||||
unsigned int depth; //not presently used
|
|
||||||
|
|
||||||
char _booleanvalues;
|
|
||||||
/* this may change; will have to analyze returned packets
|
|
||||||
0x01 = old
|
|
||||||
0x02 = lan
|
|
||||||
0x04 = proxy
|
|
||||||
0x08 = proxy pointer
|
|
||||||
0x10 = dedicated
|
|
||||||
0x20 = secure
|
|
||||||
0x40 = password
|
|
||||||
0x80 = linux
|
|
||||||
*/
|
|
||||||
unsigned int IntServerAddress;
|
|
||||||
unsigned int IntServerPort;
|
|
||||||
unsigned int last_heartbeat; //that's for timeout
|
|
||||||
unsigned int hashvalue;
|
|
||||||
|
|
||||||
unsigned short int players;
|
|
||||||
unsigned short int maxplayers;
|
|
||||||
unsigned short int fakeplayers;
|
|
||||||
|
|
||||||
struct ActiveMods_s * GameDir;
|
|
||||||
char proxyserver[64]; //seems to hold an IP address in text form.
|
|
||||||
char map[64]; //64 seems to be hardcoded in the responses
|
|
||||||
|
|
||||||
#define CheckboolIsServerOld() _booleanvalues & 0x01
|
|
||||||
#define CheckboolIsServerLan() _booleanvalues & 0x02
|
|
||||||
#define CheckboolIsServerProxy() _booleanvalues & 0x04
|
|
||||||
#define CheckboolIsServerProxyPointer() _booleanvalues & 0x08
|
|
||||||
#define CheckboolIsServerDedicated() _booleanvalues & 0x10
|
|
||||||
#define CheckboolIsServerSecure() _booleanvalues & 0x20
|
|
||||||
#define CheckboolIsServerPassworded() _booleanvalues & 0x40
|
|
||||||
#define CheckboolIsServerLinux() _booleanvalues & 0x80
|
|
||||||
|
|
||||||
#define SetboolIsServerOld() _booleanvalues |= 0x01
|
|
||||||
#define SetboolIsServerLan() _booleanvalues |= 0x02
|
|
||||||
#define SetboolIsServerProxy() _booleanvalues |= 0x04
|
|
||||||
#define SetboolIsServerProxyPointer() _booleanvalues |= 0x08
|
|
||||||
#define SetboolIsServerDedicated() _booleanvalues |= 0x10
|
|
||||||
#define SetboolIsServerSecure() _booleanvalues |= 0x20
|
|
||||||
#define SetboolIsServerPassworded() _booleanvalues |= 0x40
|
|
||||||
#define SetboolIsServerLinux() _booleanvalues |= 0x80
|
|
||||||
|
|
||||||
#define ClearboolIsServerOld() _booleanvalues &= 0xFE
|
|
||||||
#define ClearboolIsServerLan() _booleanvalues &= 0xFD
|
|
||||||
#define ClearboolIsServerProxy() _booleanvalues &= 0xFB
|
|
||||||
#define ClearboolIsServerProxyPointer() _booleanvalues &= 0xF7
|
|
||||||
#define ClearboolIsServerDedicated() _booleanvalues &= 0xEF
|
|
||||||
#define ClearboolIsServerSecure() _booleanvalues &= 0xDF
|
|
||||||
#define ClearboolIsServerPassworded() _booleanvalues &= 0xBF
|
|
||||||
#define ClearboolIsServerLinux() _booleanvalues &= 0x7F
|
|
||||||
|
|
||||||
} HLserver_t;
|
|
||||||
|
|
||||||
/* The class */
|
|
||||||
|
|
||||||
typedef class ServerList {
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/* lists */
|
|
||||||
HLserver_t * BeginningOfServerlist;
|
|
||||||
HLserver_t * FirstFreeNode;
|
|
||||||
unsigned int ReserveNodes;
|
|
||||||
unsigned int ServerTimeoutValueInSeconds;
|
|
||||||
|
|
||||||
void DeallocateServers();
|
|
||||||
void DeallocateReserveNodes();
|
|
||||||
|
|
||||||
HLserver_t * FindNodeByHash(unsigned long int);
|
|
||||||
HLserver_t * FindNodeofEqualorLesserHash(unsigned long int);
|
|
||||||
|
|
||||||
int ServerTypeCheck(const HLserver_t *, int, const char*);
|
|
||||||
bool AreServersTimingOut;
|
|
||||||
bool HaveServersEverTimedOut;
|
|
||||||
/* Thread related */
|
|
||||||
typedef void* (*lpfn_ServerTimeouts)(void *);
|
|
||||||
lpfn_ServerTimeouts orig_ThreadServerTimeouts;
|
|
||||||
pthread_t ThreadServerTimeouts;
|
|
||||||
static void ServerTimeouts(void *);
|
|
||||||
pthread_mutex_t Serverlist_lock;
|
|
||||||
pthread_mutexattr_t Serverlist_lockAttribute;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
unsigned int HashServer(struct sockaddr_in);
|
|
||||||
unsigned int HashServerIP(unsigned long int, unsigned short int);
|
|
||||||
|
|
||||||
//Todo: move this from packetry to srvrntwk
|
|
||||||
HLserver_t * FindNodeBySockaddr(struct sockaddr_in);
|
|
||||||
HLserver_t * FindNodeByIP(char);
|
|
||||||
|
|
||||||
HLserver_t * NewNode();
|
|
||||||
void FreeUnlinkedNode(HLserver_t *);
|
|
||||||
void AddNode(HLserver_t *);
|
|
||||||
void DeleteNode(HLserver_t *);
|
|
||||||
unsigned long int FillPacketBufferWithIPs(unsigned long int*, const char*, const unsigned int, const int, const char*);
|
|
||||||
//int AssignHeartbeatValuesFromPacket(struct HLserver*, const char*);
|
|
||||||
|
|
||||||
int SetServerToTimeoutInOneMin(struct sockaddr_in);
|
|
||||||
int ResetServerTimeout(struct sockaddr_in);
|
|
||||||
int SpawnServerTimeouts();
|
|
||||||
void ChangeServerTimeoutValue(unsigned int);
|
|
||||||
|
|
||||||
void FlushServers();
|
|
||||||
/* constructor/destructor */
|
|
||||||
ServerList();
|
|
||||||
~ServerList();
|
|
||||||
} ServerList_c;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
To do:
|
|
||||||
|
|
||||||
Make a releasable mod server.
|
|
||||||
Add in the 'that can't possibly happen' error checking
|
|
||||||
Allow server to be forced to listen on a specific IP
|
|
||||||
@@ -1,179 +0,0 @@
|
|||||||
#include "WONnetwk.h"
|
|
||||||
|
|
||||||
/*** Constructor/Destructor and related ***/
|
|
||||||
|
|
||||||
/* DESCRIPTION: All of the class management stuff
|
|
||||||
//
|
|
||||||
// A little differen from how I normally describe things...
|
|
||||||
// The constructor nulls the lists, the destructor deallocates them.
|
|
||||||
// The three deallocation functions are all identical save for the name
|
|
||||||
// of the list they work off of. Also can be used to force a refresh.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
WON2ServerNetwork::WON2ServerNetwork() {
|
|
||||||
|
|
||||||
/* Thread locks */
|
|
||||||
pthread_mutexattr_init(&WONnetwk_linklist_lockAttribute);
|
|
||||||
pthread_mutexattr_init(&WONnetwk_packet_lockAttribute);
|
|
||||||
pthread_mutexattr_settype(&WONnetwk_linklist_lockAttribute, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
pthread_mutexattr_settype(&WONnetwk_packet_lockAttribute, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
pthread_mutex_init(&WONnetwk_linklist_lock, &WONnetwk_linklist_lockAttribute);
|
|
||||||
pthread_mutex_init(&WONnetwk_packet_lock, &WONnetwk_packet_lockAttribute);
|
|
||||||
|
|
||||||
Mods = NULL;
|
|
||||||
NumMods = 0;
|
|
||||||
|
|
||||||
Remake_w_replypacket();
|
|
||||||
|
|
||||||
}
|
|
||||||
WON2ServerNetwork::~WON2ServerNetwork() {
|
|
||||||
|
|
||||||
DeallocateMods();
|
|
||||||
|
|
||||||
pthread_mutexattr_destroy(&WONnetwk_linklist_lockAttribute);
|
|
||||||
pthread_mutexattr_destroy(&WONnetwk_packet_lockAttribute);
|
|
||||||
pthread_mutex_destroy(&WONnetwk_linklist_lock);
|
|
||||||
pthread_mutex_destroy(&WONnetwk_packet_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
//These three are too small to bother combining into one.
|
|
||||||
void WON2ServerNetwork::DeallocateMods() {
|
|
||||||
|
|
||||||
WON2Modlist_t* ptr;
|
|
||||||
pthread_mutex_lock(&WONnetwk_linklist_lock);
|
|
||||||
while(Mods != NULL) {
|
|
||||||
ptr = Mods;
|
|
||||||
Mods = Mods->next;
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
NumMods = 0;
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&WONnetwk_linklist_lock);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void WON2ServerNetwork::RetrieveMods(void **name) {
|
|
||||||
|
|
||||||
WON2Modlist_t *ptr = (WON2Modlist_t*)*name;
|
|
||||||
|
|
||||||
|
|
||||||
if(ptr == NULL) {
|
|
||||||
ptr = Mods;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(ptr != NULL && ptr->IsLoaded != 1) {
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
//At this stage we have a ptr variable which points to a valid master
|
|
||||||
//entry, or to NULL, meaning we should just leave.
|
|
||||||
|
|
||||||
if(ptr == NULL) {
|
|
||||||
*name = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*name = (void *)ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long int ModList::FillPacketBufferWithMods(const char * StartMod, char * buffer, const unsigned int SizeOfBuffer) {
|
|
||||||
|
|
||||||
unsigned int packetlen = 0;
|
|
||||||
WON2Modlist_t * ptr;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&ModList_linklist_lock);
|
|
||||||
|
|
||||||
ptr = CurrentMods;
|
|
||||||
|
|
||||||
if(strcmp(StartMod, "start-of-list") != 0) {
|
|
||||||
|
|
||||||
while(ptr != NULL && strncasecmp(ptr->Name, StartMod, 63) != 0) {
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while(ptr != NULL) {
|
|
||||||
|
|
||||||
if(packetlen >= SizeOfBuffer - (36 + strlen(ptr->Name))) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
packetlen += 1 + sprintf(buffer + packetlen, "%s", ptr->Name);
|
|
||||||
while(ptr->tokens)
|
|
||||||
packetlen += 1 + sprintf(buffer + packetlen, "%u", ptr->tokens);
|
|
||||||
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ptr == NULL) { //finished successfully
|
|
||||||
memcpy(buffer + packetlen, "end-of-list", sizeof("end-of-list"));
|
|
||||||
packetlen += sizeof("end-of-list");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
memcpy(buffer + packetlen, "more-in-list", sizeof("more-in-list"));
|
|
||||||
packetlen += sizeof("more-in-list");
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&ModList_linklist_lock);
|
|
||||||
|
|
||||||
return(packetlen);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: AddMod
|
|
||||||
*/
|
|
||||||
char WON2ServerNetwork::AddMod(const char *arg, WON2Modlist_t **modlist, WON2Modlist_t *toke ) {
|
|
||||||
|
|
||||||
char temparray[10];
|
|
||||||
char modvar;
|
|
||||||
|
|
||||||
strncpy(temparray, arg, 9);
|
|
||||||
|
|
||||||
//For now let's malloc the structure we'll definitely need.
|
|
||||||
|
|
||||||
WON2Modlist_t * NewMod = (WON2Modlist_t *)malloc(sizeof(WON2Modlist_t));
|
|
||||||
if(NewMod == NULL) { return(3); } //BAIL! Bad things, man.
|
|
||||||
|
|
||||||
NewMod->previous = NULL;
|
|
||||||
NewMod->Name = NULL;
|
|
||||||
|
|
||||||
//Copy the name and resolve it.
|
|
||||||
NewMod->Name = new std::string(temparray);
|
|
||||||
|
|
||||||
//At this point we have a valid node. Add it onto the beginning of our list.
|
|
||||||
|
|
||||||
NewMod->next = (*modlist);
|
|
||||||
if((*modlist) != NULL) {
|
|
||||||
(*modlist)->previous = NewMod;
|
|
||||||
}
|
|
||||||
(*modlist) = NewMod;
|
|
||||||
|
|
||||||
RetrieveMods(temparray);
|
|
||||||
|
|
||||||
Remake_w_replypacket();
|
|
||||||
|
|
||||||
return(temparray);
|
|
||||||
}
|
|
||||||
|
|
||||||
char WON2ServerNetwork::AddMod(char *arg, WON2Modlist_t *tokens) {
|
|
||||||
|
|
||||||
char returnValue;
|
|
||||||
pthread_mutex_lock(&WONnetwk_linklist_lock);
|
|
||||||
|
|
||||||
returnValue = AddMod(arg, &Mods, tokens);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&WONnetwk_linklist_lock);
|
|
||||||
|
|
||||||
if(returnValue == 0 || returnValue == 1) { NumMods++; }
|
|
||||||
return(returnValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void WON2ServerNetwork::send_IN_w_ReplyPacket(struct sockaddr_in DestinationAddress) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&WONnetwk_packet_lock);
|
|
||||||
|
|
||||||
ptrSocketClass->OUT_SendSpecificReply(OUT_w_replyingpacket, OUT_w_replyingpacketsize, DestinationAddress);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&WONnetwk_packet_lock);
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/* This class deals with the management of other masters on the network.
|
|
||||||
// It's also being designed with both auth and titan servers in mind. Many
|
|
||||||
// of the actions have three variants dealing with the three unique servers,
|
|
||||||
// and one base function that actually does the modifications.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__WON2_SERVER_NETWORK_H_
|
|
||||||
#define __MASTER__SERVER__WON2_SERVER_NETWORK_H_
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include "port.h"
|
|
||||||
#include "externs.h"
|
|
||||||
#include "packetry.h"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifndef MAX_PACKET_LENGTH
|
|
||||||
#define MAX_PACKET_LENGTH 1400
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*** Structs ***/
|
|
||||||
typedef struct WON2modlist_s {
|
|
||||||
struct WON2modlist_s *next, *previous; //tree linkage
|
|
||||||
std::string *Name; //Transistor pointed out that most of our servers are on dynamic IPs
|
|
||||||
int *uniqueid;
|
|
||||||
char *game;
|
|
||||||
char *gdir;
|
|
||||||
char *url_dl;
|
|
||||||
char *url_info;
|
|
||||||
double *version;
|
|
||||||
int *size
|
|
||||||
char *type;
|
|
||||||
|
|
||||||
} WON2Modlist_t;
|
|
||||||
|
|
||||||
/*** The class ***/
|
|
||||||
|
|
||||||
typedef class WON2ServerNetwork {
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/* lists */
|
|
||||||
WON2Modlist_t *Mods;
|
|
||||||
|
|
||||||
unsigned int NumMods;
|
|
||||||
|
|
||||||
void DeallocateMods();
|
|
||||||
|
|
||||||
char AddMod(const char *, WON2Modlist_t **);
|
|
||||||
|
|
||||||
void Remake_w_replypacket();
|
|
||||||
char OUT_w_replyingpacket[MAX_PACKET_LENGTH];
|
|
||||||
unsigned int OUT_w_replyingpacketsize;
|
|
||||||
|
|
||||||
/* Thread related */
|
|
||||||
pthread_mutexattr_t WONnetwk_linklist_lockAttribute;
|
|
||||||
pthread_mutexattr_t WONnetwk_packet_lockAttribute;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/* Thread locks */
|
|
||||||
pthread_mutex_t WONnetwk_linklist_lock;
|
|
||||||
pthread_mutex_t WONnetwk_packet_lock;
|
|
||||||
|
|
||||||
//A little overloading...
|
|
||||||
char AddMod(char *);
|
|
||||||
|
|
||||||
void send_IN_w_ReplyPacket(struct sockaddr_in);
|
|
||||||
|
|
||||||
/* constructor/destructor */
|
|
||||||
WON2ServerNetwork();
|
|
||||||
~WON2ServerNetwork();
|
|
||||||
} WON2ServerNetwork_c;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,261 +0,0 @@
|
|||||||
#include "banlist.h"
|
|
||||||
|
|
||||||
/******** Local macros ********/
|
|
||||||
|
|
||||||
/* Description: CompareIPs
|
|
||||||
//
|
|
||||||
// Takes two IPs and compares them. Since they're just
|
|
||||||
// ints, that's not a big deal.
|
|
||||||
*/
|
|
||||||
#define CompareIPs(IPa,IPb) ((IPa)==(IPb))
|
|
||||||
|
|
||||||
|
|
||||||
/* Description: CompareIPs
|
|
||||||
//
|
|
||||||
// Takes two IPs and compares them, with a subnet mask
|
|
||||||
// ANDed to them both. Network order, always.
|
|
||||||
*/
|
|
||||||
#define CompareIPsWithCIDR(IPa,IPb,Maskc) (((IPa)&(Maskc))==((IPb)&(Maskc)))
|
|
||||||
|
|
||||||
/******** Constructor/Destructor ********/
|
|
||||||
|
|
||||||
IPBanList::IPBanList() {
|
|
||||||
pthread_mutex_init(&Banlist_undesirables_lock, NULL);
|
|
||||||
BeginningOfBanlist = NULL;
|
|
||||||
|
|
||||||
//Since 0 and -1 are special addresses that also double as invalid catches,
|
|
||||||
//ban them outright.
|
|
||||||
BanIP(0, htonl(0xFF000000));
|
|
||||||
BanIP(INADDR_NONE, htonl(0xFF000000));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
IPBanList::~IPBanList() {
|
|
||||||
|
|
||||||
IPBanListStructure_t* ptr;
|
|
||||||
while(BeginningOfBanlist != NULL) {
|
|
||||||
ptr = BeginningOfBanlist;
|
|
||||||
BeginningOfBanlist = BeginningOfBanlist->next;
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
pthread_mutex_destroy(&Banlist_undesirables_lock);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**** SockAddr ban functions ****/
|
|
||||||
|
|
||||||
/* DESCRIPTION: BanSockaddr
|
|
||||||
//
|
|
||||||
// Takes a sockaddr, and calls BanIP with the sockaddr's address.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int IPBanList::BanSockaddr(struct sockaddr_in sender) {
|
|
||||||
|
|
||||||
return(BanIP(sender.sin_addr.s_addr, 0xFFFFFFFF));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: UnbanSockaddr
|
|
||||||
//
|
|
||||||
// Just strips the IP and calls the corresponding IP function.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int IPBanList::UnbanSockaddr(struct sockaddr_in sender) {
|
|
||||||
return(UnbanIP(sender.sin_addr.s_addr, 0xFFFFFFFF));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: IsSockaddrBanned
|
|
||||||
//
|
|
||||||
// Takes a sockaddr, strips out the sin_addr, and passes it on as an int.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int IPBanList::IsSockaddrBanned(struct sockaddr_in sender) {
|
|
||||||
|
|
||||||
return(IsIPBanned(sender.sin_addr.s_addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**** IPAddr ban functions ****/
|
|
||||||
|
|
||||||
/* DESCRIPTION: BanIP
|
|
||||||
//
|
|
||||||
// Mallocs a new IPBanStructure and copies the passed int in, after checking
|
|
||||||
// to see if it's banned or not. Freed in the destructor.
|
|
||||||
//
|
|
||||||
// Reutns 0 on success, or 1 if the address is already banned.
|
|
||||||
*/
|
|
||||||
int IPBanList::BanIP(unsigned long int senderIP, unsigned long int CIDR) {
|
|
||||||
|
|
||||||
if(IsIPBanned(senderIP & CIDR)) { return(1); }
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Banlist_undesirables_lock);
|
|
||||||
|
|
||||||
IPBanListStructure_t * ptr = (IPBanListStructure_t *)malloc(sizeof(IPBanListStructure_t));
|
|
||||||
ptr->next = BeginningOfBanlist;
|
|
||||||
ptr->address = senderIP;
|
|
||||||
ptr->subnetmask = CIDR;
|
|
||||||
BeginningOfBanlist = ptr;
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Banlist_undesirables_lock);
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: UnbanIP
|
|
||||||
//
|
|
||||||
// Searches for and removes (frees) an IP that is passed.
|
|
||||||
// Returns 0 on success or 255 if the IP wasn't present.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int IPBanList::UnbanIP(unsigned long int senderIP, unsigned long int CIDR) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Banlist_undesirables_lock);
|
|
||||||
|
|
||||||
IPBanListStructure_t* ptr = BeginningOfBanlist;
|
|
||||||
IPBanListStructure_t* ptr2 = NULL;
|
|
||||||
|
|
||||||
while(ptr != NULL) {
|
|
||||||
|
|
||||||
if(CompareIPs(senderIP, ptr->address) && (CIDR == (ptr->subnetmask))) {
|
|
||||||
if(ptr2 == NULL) { //First IP in the list
|
|
||||||
BeginningOfBanlist = BeginningOfBanlist->next;
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptr2->next = ptr->next;
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Banlist_undesirables_lock);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr2 = ptr;
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Banlist_undesirables_lock);
|
|
||||||
|
|
||||||
return(255);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: IsIPBanned
|
|
||||||
//
|
|
||||||
// Takes an unsigned int (can be any of the S_un structs typecast)
|
|
||||||
// for comparison, and compares them to the ban list.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int IPBanList::IsIPBanned(unsigned long int senderIP) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&Banlist_undesirables_lock);
|
|
||||||
|
|
||||||
IPBanListStructure_t* ptr = BeginningOfBanlist;
|
|
||||||
while(ptr != NULL) {
|
|
||||||
if(CompareIPsWithCIDR(senderIP, ptr->address, ptr->subnetmask) == 1) {
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Banlist_undesirables_lock);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&Banlist_undesirables_lock);
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: ParseBanString
|
|
||||||
//
|
|
||||||
// Parses a string from input into a workable ban.
|
|
||||||
// Returns 0 on success.
|
|
||||||
//
|
|
||||||
// Examples: (input will remove the preceding 'ban')
|
|
||||||
// 4.224.234.200 //bans that address
|
|
||||||
// 3.3.3.3 255.255.255.0 //bans all 3.3.3.x addresses
|
|
||||||
// 3.3.3.0/23 // bans anything on 3.3.[2-3].x I think.
|
|
||||||
*/
|
|
||||||
int IPBanList::ParseBanString(const char *arg, const char ToBanOrNotToBan) {
|
|
||||||
|
|
||||||
char temparray[80];
|
|
||||||
char *ptr = NULL;
|
|
||||||
unsigned int IPaddress;
|
|
||||||
unsigned int CIDR = 0xFFFFFFFF;
|
|
||||||
short int temp;
|
|
||||||
|
|
||||||
strncpy(temparray, arg, 79);
|
|
||||||
|
|
||||||
ptr = strpbrk(temparray, " /"); // Is there a space or a slash afterwards?
|
|
||||||
if(ptr != NULL) { // Yes there is.
|
|
||||||
|
|
||||||
ptr[0] = '\0';
|
|
||||||
do { ptr++; } while(*ptr == ' ' || *ptr == '/');
|
|
||||||
|
|
||||||
temp = atoi(ptr);
|
|
||||||
if(temp < 1 || temp > 32) { //Not CIDR. Don't be fooled by the var names
|
|
||||||
CIDR = inet_addr(ptr);
|
|
||||||
}
|
|
||||||
else { //else it must be that CIDR notation.
|
|
||||||
CIDR = 0;
|
|
||||||
for(IPaddress = 0; IPaddress < 32; IPaddress++) { //Var reuse as a counter.
|
|
||||||
|
|
||||||
if(temp >= 0) {
|
|
||||||
temp--;
|
|
||||||
CIDR++;
|
|
||||||
}
|
|
||||||
CIDR = CIDR<<1;
|
|
||||||
}
|
|
||||||
CIDR = htonl(CIDR);
|
|
||||||
}
|
|
||||||
if (CIDR == INADDR_NONE || CIDR == 0) { //banning everyone sounds a lil extreme
|
|
||||||
return(126);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Now for the actual address.
|
|
||||||
|
|
||||||
IPaddress = inet_addr(temparray);
|
|
||||||
|
|
||||||
if (IPaddress == INADDR_NONE || IPaddress == 0) {
|
|
||||||
// Not an Ip address. That's bad.
|
|
||||||
return(127);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ToBanOrNotToBan) { //Or, did the user type 'un' in front of that 'ban'?
|
|
||||||
return(BanIP(IPaddress, CIDR));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return(UnbanIP(IPaddress, CIDR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTON: RetrieveBanlist
|
|
||||||
//
|
|
||||||
// Much like the WONnetwk function.
|
|
||||||
// They pass us a void pointer, we return numbers.
|
|
||||||
*/
|
|
||||||
void IPBanList::RetrieveBanlist(void **address, unsigned long int* IP, unsigned long int* CIDR) {
|
|
||||||
|
|
||||||
IPBanListStructure_t *ptr = (IPBanListStructure_t*)*address;
|
|
||||||
|
|
||||||
|
|
||||||
if(ptr == NULL) {
|
|
||||||
ptr = BeginningOfBanlist;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
//At this stage we have a ptr variable which points to a valid master
|
|
||||||
//entry, or to NULL, meaning we should just leave.
|
|
||||||
|
|
||||||
if(ptr == NULL) {
|
|
||||||
*address = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*address = (void *)ptr;
|
|
||||||
*CIDR = ptr->subnetmask;
|
|
||||||
*IP = ptr->address;
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
//
|
|
||||||
// A class for handling the relatively simple task of dropping packets
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
#ifndef __MASTER__SERVER__BANLIST_H_
|
|
||||||
#define __MASTER__SERVER__BANLIST_H_
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include "port.h" //so it recognizes sockaddr_in
|
|
||||||
|
|
||||||
/*** The class ***/
|
|
||||||
|
|
||||||
//An IP linked list. May eventually be tree. Almost, but not quite, entirely
|
|
||||||
//unlike sin_addr. But we need that pointer.
|
|
||||||
|
|
||||||
typedef struct IPBanListStructure_s {
|
|
||||||
unsigned long int address;
|
|
||||||
unsigned long int subnetmask;
|
|
||||||
struct IPBanListStructure_s *next;
|
|
||||||
} IPBanListStructure_t;
|
|
||||||
|
|
||||||
typedef class IPBanList {
|
|
||||||
|
|
||||||
private:
|
|
||||||
IPBanListStructure_t * BeginningOfBanlist;
|
|
||||||
|
|
||||||
public:
|
|
||||||
IPBanList();
|
|
||||||
~IPBanList();
|
|
||||||
|
|
||||||
// And the basic thread protection:
|
|
||||||
pthread_mutex_t Banlist_undesirables_lock;
|
|
||||||
|
|
||||||
int BanSockaddr(struct sockaddr_in);
|
|
||||||
int UnbanSockaddr(struct sockaddr_in);
|
|
||||||
int IsSockaddrBanned(struct sockaddr_in);
|
|
||||||
|
|
||||||
int BanIP(unsigned long int, unsigned long int); //s_addr may be typecast to int
|
|
||||||
int UnbanIP(unsigned long int, unsigned long int);
|
|
||||||
int IsIPBanned(unsigned long int);
|
|
||||||
|
|
||||||
void RetrieveBanlist(void **address, unsigned long int* IP, unsigned long int* CIDR);
|
|
||||||
|
|
||||||
|
|
||||||
int ParseBanString(const char*, const char);
|
|
||||||
} IPBanList_c;
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
#include "chalnum.h"
|
|
||||||
|
|
||||||
/******** Constructor/Destructor ********/
|
|
||||||
|
|
||||||
ChallengeList::ChallengeList() {
|
|
||||||
PurgeAllChallenges();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: PurgeAllChallenges
|
|
||||||
//
|
|
||||||
// Zeros out the array. Called by the constructor. It doesn't appear to
|
|
||||||
// be necessary, as it's zeroed in the debugger regardless; could be compiler
|
|
||||||
// specific though, so I'll leave it.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void ChallengeList::PurgeAllChallenges() {
|
|
||||||
|
|
||||||
memset(ChallengeNumbers, 0xFFFFFFFF, sizeof(ChallengeNumbers));
|
|
||||||
memset(ChallengeAddresses, 0, sizeof(ChallengeAddresses));
|
|
||||||
memset(ArrayPositions, 0, sizeof(ArrayPositions));
|
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
HashBase = ((rand() ^ (rand()<<17)) ^ (rand()<<9)); //RAND_MAX is 7FFF for my libs.
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: ComputeHash
|
|
||||||
//
|
|
||||||
// Computes a hash. A hash of a 32 bit number, that is. There are three
|
|
||||||
// requirements: even distribution, values will not necessarially return the
|
|
||||||
// same hash when the program is stopped and restarted, and values that all
|
|
||||||
// share the same hash in one program instance should be split up in another.
|
|
||||||
//
|
|
||||||
// Even distribution is met. So are unique individual hashes. After trying
|
|
||||||
// many things, I was able to reduce clumping, but there are definitely
|
|
||||||
// patterns in the distribution. I tried; I'm not a hashing expert, but it
|
|
||||||
// does do all three, and it should be at a level where predicting and DoSing
|
|
||||||
// someone's challenge requests should be next to impossible without luck or a
|
|
||||||
// full blown denial of service attack.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
unsigned int ChallengeList::ComputeHash(unsigned long int senderIP) {
|
|
||||||
|
|
||||||
//BINARY_SHIFT is a define, replacing that ugly mod (%).
|
|
||||||
return(((senderIP + HashBase) ^ ((senderIP + HashBase)<<16) | ((senderIP+ HashBase)>>16))BINARY_SHIFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: AssignChallengeaddr
|
|
||||||
//
|
|
||||||
// Merely calls the corresponding IP function.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
signed long int ChallengeList::AssignChallengeaddr(struct sockaddr_in sender) {
|
|
||||||
|
|
||||||
return(AssignChallengeIP(sender.sin_addr.s_addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: VerifyChallengeaddr
|
|
||||||
//
|
|
||||||
// Just calls the IP function as it is needed.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
char ChallengeList::VerifyChallengeaddr(struct sockaddr_in sender, signed long int PassedChallenge) {
|
|
||||||
|
|
||||||
return(VerifyChallengeIP(sender.sin_addr.s_addr, PassedChallenge));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: AssignChallengeIP
|
|
||||||
//
|
|
||||||
// Takes an IP, computes a random 'challenge value' (which is returned), and
|
|
||||||
// then adds that number AND the address to our big table O challenges.
|
|
||||||
// The bulk of the code is actually for the situation where we still HAVE an
|
|
||||||
// an active challenge for the sender; in that case we do some reorganizing.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
signed long int ChallengeList::AssignChallengeIP(unsigned long int senderIP) {
|
|
||||||
|
|
||||||
signed int challenge = 0;
|
|
||||||
unsigned int ServerHash = ComputeHash(senderIP);
|
|
||||||
|
|
||||||
//We add our challenge number to our table.
|
|
||||||
//Sort've. First we have to check if they have one already.
|
|
||||||
|
|
||||||
for(int i = 0; i < ELEMENTS_PER_HASH; i++) {
|
|
||||||
if(ChallengeAddresses[ServerHash][i] == senderIP) {
|
|
||||||
//Hey, they still have one. Return it to them, and reorder the list.
|
|
||||||
|
|
||||||
|
|
||||||
challenge = ChallengeNumbers[ServerHash][i];
|
|
||||||
|
|
||||||
while(i != ArrayPositions[ServerHash]) {
|
|
||||||
if(i+1 < ELEMENTS_PER_HASH) {
|
|
||||||
ChallengeAddresses[ServerHash][i] = ChallengeAddresses[ServerHash][i+1];
|
|
||||||
ChallengeNumbers[ServerHash][i] = ChallengeNumbers[ServerHash][i+1];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ChallengeAddresses[ServerHash][i] = ChallengeAddresses[ServerHash][0];
|
|
||||||
ChallengeNumbers[ServerHash][i] = ChallengeNumbers[ServerHash][0];
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ChallengeAddresses[ServerHash][i] = senderIP;
|
|
||||||
ChallengeNumbers[ServerHash][i] = challenge;
|
|
||||||
|
|
||||||
|
|
||||||
ArrayPositions[ServerHash] = (i++) ELEMENTS_PER_HASH_MOD;
|
|
||||||
return(challenge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//We get to here, then they have no challenge number and need one.
|
|
||||||
|
|
||||||
challenge = ((rand() | (rand()<<17) | (rand()<<9)) & 0x7FFFFFFF);
|
|
||||||
|
|
||||||
/* Explanation time: For some reason HL never sends a challenge with
|
|
||||||
// the first bit as a 1. Is this intentional, or an issue with their rand?
|
|
||||||
// Doesn't matter, but just in case I do the same thing. Another issue is
|
|
||||||
// we need to have some sort of 'never assigned' value to default to when
|
|
||||||
// allocating the memory so people can't guess that value and have it work.
|
|
||||||
// Since we never have the last bit set, I chose 0xFFFFFFFF as that value
|
|
||||||
// (check the constructor). It's also checked for and rejected in the
|
|
||||||
// VerifyChallengeIP function--so we should be safe from the defaults.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Now just replace the oldest element and be done.
|
|
||||||
|
|
||||||
ChallengeAddresses[ServerHash][ArrayPositions[ServerHash]] = senderIP;
|
|
||||||
ChallengeNumbers[ServerHash][ArrayPositions[ServerHash]] = challenge;
|
|
||||||
|
|
||||||
//Whew! That was hard. Let's go grab some beers.
|
|
||||||
|
|
||||||
return(challenge);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: VerifyChallengeIP
|
|
||||||
//
|
|
||||||
// A very quick search and return. 1 means we found it, 0 means you're SOL.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
char ChallengeList::VerifyChallengeIP(unsigned long int senderIP, signed long int PassedChallenge) {
|
|
||||||
|
|
||||||
if(PassedChallenge & 0x80000000) {
|
|
||||||
return(0);
|
|
||||||
} //good guesser guard
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int ServerHash = ComputeHash(senderIP);
|
|
||||||
|
|
||||||
for(int i = 0; i < ELEMENTS_PER_HASH; i++) {
|
|
||||||
if(ChallengeAddresses[ServerHash][i] == senderIP) {
|
|
||||||
if(ChallengeNumbers[ServerHash][i] == PassedChallenge) {
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
//
|
|
||||||
// This class deals with challenge numbers. In Half-Life challenge numbers
|
|
||||||
// exist mainly to prevent IP spoofing, and to prevent having servers be
|
|
||||||
// unwitting participants in DDoS attacks. The HL servers don't pull it off
|
|
||||||
// so well, but there's no reason why we shouldn't. Especially since it's part
|
|
||||||
// of the engine and we have to anyway :).
|
|
||||||
//
|
|
||||||
// Basically we get a request for a challenge and we pass it to this class.
|
|
||||||
// The class will store it, and the IP of the requester, in some sort of table.
|
|
||||||
// The table has a finite size and as elements are added old ones are removed.
|
|
||||||
// To prevent a serious DoS attack, some sort of hashing must be used so that
|
|
||||||
// if someone issues out many challenges they will only succeed in filling up
|
|
||||||
// their block, denying only themselves and a few other IPs unfortunate to
|
|
||||||
// share the hash of the master server. Later, when a challenge number is
|
|
||||||
// received, this class will verify its authenticity.
|
|
||||||
//
|
|
||||||
// Oh yeah. Don't call this baby statically. You'll kill the stack. Always
|
|
||||||
// declare this class with malloc or new.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
#include "port.h" //port includes networking stuff
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h> //need rand();
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__CHALNUM_H_
|
|
||||||
#define __MASTER__SERVER__CHALNUM_H_
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_HASH_VALUE 4096
|
|
||||||
#define ELEMENTS_PER_HASH 16
|
|
||||||
#define BINARY_SHIFT >>20 //If you change MAX_HASH_VALUE do it here too
|
|
||||||
#define ELEMENTS_PER_HASH_MOD & 0x0000000F//equiv to a "% ELEMENTS_PER_HASH
|
|
||||||
//that's about 8 megs of memory for what we want by my count
|
|
||||||
|
|
||||||
/*** The class ***/
|
|
||||||
|
|
||||||
|
|
||||||
// Only one class exists, but it's self-contained. You could add more.
|
|
||||||
typedef class ChallengeList {
|
|
||||||
|
|
||||||
private:
|
|
||||||
signed long int ChallengeNumbers[MAX_HASH_VALUE][ELEMENTS_PER_HASH];
|
|
||||||
unsigned long int ChallengeAddresses[MAX_HASH_VALUE][ELEMENTS_PER_HASH];
|
|
||||||
unsigned char ArrayPositions[MAX_HASH_VALUE];
|
|
||||||
int HashBase;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ChallengeList(); //For zeroing it out.
|
|
||||||
|
|
||||||
void PurgeAllChallenges(); //Eh; we might need it.
|
|
||||||
|
|
||||||
char VerifyChallengeaddr(struct sockaddr_in, signed long int);
|
|
||||||
char VerifyChallengeIP(unsigned long int, signed long int);
|
|
||||||
|
|
||||||
signed long int AssignChallengeaddr(struct sockaddr_in);
|
|
||||||
signed long int AssignChallengeIP(unsigned long int);
|
|
||||||
unsigned int ComputeHash(unsigned long int);
|
|
||||||
|
|
||||||
} ChallengeList_c;
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
// EXTERNS.H
|
|
||||||
//
|
|
||||||
// All of our classes will be in constant contact with each other, and
|
|
||||||
// each class will be unique. Therefore, they need to be globally accessible--
|
|
||||||
// but making the actual class objects themselves global is un bad idea.
|
|
||||||
//
|
|
||||||
// Instead, we will make pointers to all the classes and make those pointers
|
|
||||||
// globally accessible. Then, everybody wins.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__EXTERNS_H_
|
|
||||||
#define __MASTER__SERVER__EXTERNS_H_
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*** Class pointers ***/
|
|
||||||
|
|
||||||
extern class InputOutputStats * ptrIO;
|
|
||||||
extern class IPBanList * ptrBanlist;
|
|
||||||
extern class PacketManagement * ptrSocketClass;
|
|
||||||
extern class WON2ServerNetwork * ptrMods;
|
|
||||||
#endif
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
//using namespace std; //I actually prefer to insert this in all decs.
|
|
||||||
#include "input.h"
|
|
||||||
|
|
||||||
/* What window does what:
|
|
||||||
//
|
|
||||||
//stdscr: nothing directly, unless you count input.
|
|
||||||
//StatsWindow: Updates every second unless menu is running.
|
|
||||||
//OutputWindow: Updates only when menu isn't running.
|
|
||||||
//
|
|
||||||
//BaseMenuWindow: All menu windows derived from this. Separates menu from stdscr.
|
|
||||||
//QuitWindow: Small window for prompting a quit.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******** Constructor/Destructor ********/
|
|
||||||
|
|
||||||
InputOutputStats::InputOutputStats() {
|
|
||||||
|
|
||||||
TotalMods = 0;
|
|
||||||
|
|
||||||
CurrentTime = (unsigned int)time(NULL);
|
|
||||||
debuglevel = 1;
|
|
||||||
filedebuglevel = 0;
|
|
||||||
debuglog = NULL;
|
|
||||||
port = 27011;
|
|
||||||
ConfigFile = "modlist.cfg";
|
|
||||||
|
|
||||||
}
|
|
||||||
int InputOutputStats::ProcessGameFileInput(char modname) {
|
|
||||||
|
|
||||||
struct config_t cfg;
|
|
||||||
struct config_setting_t *setting = NULL;
|
|
||||||
config_init(&cfg);
|
|
||||||
WON2Modlist_t modtoken;
|
|
||||||
|
|
||||||
if(!config_read_file(&cfg, namefile.c_str())) {
|
|
||||||
printf("Config file parsing failed. Error on line %d: %s\n", cfg.error_line, cfg.error_text);
|
|
||||||
config_destroy(&cfg);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
setting = config_lookup(&cfg, "uniqueid");
|
|
||||||
if(setting != NULL)
|
|
||||||
modtoken->uniqueid = config_setting_get_string(setting);
|
|
||||||
setting = config_lookup(&cfg, "game");
|
|
||||||
if(setting != NULL)
|
|
||||||
modtoken->game = config_setting_get_string(setting);
|
|
||||||
setting = config_lookup(&cfg, "url_info");
|
|
||||||
if(setting != NULL)
|
|
||||||
modtoken->url_info = config_setting_get_string(setting);
|
|
||||||
setting = config_lookup(&cfg, "url_dl");
|
|
||||||
if(setting != NULL)
|
|
||||||
modtoken->url_dl = config_setting_get_string(setting);
|
|
||||||
setting = config_lookup(&cfg, "version");
|
|
||||||
if(setting != NULL)
|
|
||||||
modtoken->version = config_setting_get_string(setting);
|
|
||||||
setting = config_lookup(&cfg, "size");
|
|
||||||
if(setting != NULL)
|
|
||||||
modtoken->size = config_setting_get_int(setting);
|
|
||||||
setting = config_lookup(&cfg, "type");
|
|
||||||
if(setting != NULL)
|
|
||||||
modtoken->type = config_setting_get_string(setting);
|
|
||||||
|
|
||||||
ptrMods->AddMod(modname, modtoken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: ProcessConfigFileInput
|
|
||||||
//
|
|
||||||
// I don't know much about libconfig, but it compiled nicely enough.
|
|
||||||
// Most of this is borrowed from the examples. I may, someday, convert
|
|
||||||
// all of the startup stuff to libraries like this.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int InputOutputStats::ProcessConfigFileInput() {
|
|
||||||
|
|
||||||
struct config_t cfg;
|
|
||||||
struct config_setting_t *setting = NULL;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
const char *modname;
|
|
||||||
config_init(&cfg);
|
|
||||||
|
|
||||||
if(!config_read_file(&cfg, ConfigFile.c_str())) {
|
|
||||||
printf("Config file parsing failed. Error on line %d: %s\n", cfg.error_line, cfg.error_text);
|
|
||||||
config_destroy(&cfg);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
setting = config_lookup(&cfg, "application.timeout");
|
|
||||||
if(setting != NULL) { boolServersTimeout = config_setting_get_bool(setting); }
|
|
||||||
|
|
||||||
setting = config_lookup(&cfg, "application.verboseness");
|
|
||||||
if(setting != NULL) {
|
|
||||||
debuglevel = config_setting_get_int(setting);
|
|
||||||
if((debuglevel < 0) || (debuglevel > 3)) {
|
|
||||||
printf("\"verboseness\" must be a value between 0 and 3.\n");
|
|
||||||
debuglevel = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("Setting console debug level to \"%i\".\n", debuglevel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setting = config_lookup(&cfg, "file.name");
|
|
||||||
if(setting != NULL) {
|
|
||||||
addresses = config_setting_get_string(setting);
|
|
||||||
if(strlen(addresses) > 0) {
|
|
||||||
DebugFile.assign(addresses);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("file.name appears to be empty. Using defaults");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setting = config_lookup(&cfg, "file.logginglevel");
|
|
||||||
if(setting != NULL) {
|
|
||||||
filedebuglevel = config_setting_get_int(setting);
|
|
||||||
if(filedebuglevel < 0) {
|
|
||||||
printf("\"logginglevel\" shouldn't be negative.\n");
|
|
||||||
filedebuglevel = 0;
|
|
||||||
}
|
|
||||||
else if(filedebuglevel > 0) {
|
|
||||||
debuglog = fopen(DebugFile.c_str(), "wb");
|
|
||||||
if(debuglog == NULL) {
|
|
||||||
perror(NULL);
|
|
||||||
filedebuglevel = -1; }
|
|
||||||
else {
|
|
||||||
printf("Setting file debug level to \"%i\".\n", filedebuglevel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setting = config_lookup(&cfg, "mods");
|
|
||||||
if(setting != NULL) {
|
|
||||||
i = config_setting_length(setting);
|
|
||||||
printf("%i mod entries.\n", i);
|
|
||||||
while(i > 0) {
|
|
||||||
i--;
|
|
||||||
modname = config_setting_get_string_elem(setting, i);
|
|
||||||
WON2Modlist_t modtoken;
|
|
||||||
j = processgamefileinput
|
|
||||||
|
|
||||||
switch(j) {
|
|
||||||
case 1:
|
|
||||||
printf("Mod failed to load.\n");
|
|
||||||
case 0:
|
|
||||||
printf("Mod added.\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setting = config_lookup(&cfg, "bans");
|
|
||||||
if(setting != NULL) {
|
|
||||||
i = config_setting_length(setting);
|
|
||||||
printf("%i bans listed.\n", i);
|
|
||||||
while(i > 0) {
|
|
||||||
i--;
|
|
||||||
j = ptrBanlist->ParseBanString(config_setting_get_string_elem(setting, i), 1);
|
|
||||||
switch(j) {
|
|
||||||
case 0:
|
|
||||||
printf("Ban added.\n");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
printf("Ban entry already exists. ");
|
|
||||||
default:
|
|
||||||
printf("Ban not added.\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config_destroy(&cfg);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: ProcessMOTDFileInput
|
|
||||||
//
|
|
||||||
// Load text from file, pipe text to MOTD. Nothing to it.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int InputOutputStats::ProcessMODFileInput(char name) {
|
|
||||||
|
|
||||||
FILE *fp;
|
|
||||||
char s[256]; //this hard limit is encoded in several places.
|
|
||||||
int i;
|
|
||||||
|
|
||||||
fp = fopen(MOTDfile.c_str(), "rb");
|
|
||||||
if(fp == NULL) { return(1); }
|
|
||||||
|
|
||||||
|
|
||||||
i = fread(s, 1, 255, fp);
|
|
||||||
s[i] = '\0';
|
|
||||||
|
|
||||||
ptrSocketClass->UpdateMOTD(s);
|
|
||||||
fclose(fp);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
//
|
|
||||||
// This class deals with all the console input, as well as parameter parsing in
|
|
||||||
// the command line.
|
|
||||||
//
|
|
||||||
// Curses is desired. This also has its own thread.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__IOS_H_
|
|
||||||
#define __MASTER__SERVER__IOS_H_
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <string>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#include "externs.h"
|
|
||||||
#include "WONnetwk.h"
|
|
||||||
#include "SrvrNtwk.h"
|
|
||||||
#include "banlist.h"
|
|
||||||
#include "port.h"
|
|
||||||
|
|
||||||
#include LIBCONFIG //make sure you include this AFTER port.h, which holds the define
|
|
||||||
/*** The class ***/
|
|
||||||
|
|
||||||
typedef class InputOutputStats {
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/* Server stats */
|
|
||||||
unsigned long int TotalMods;
|
|
||||||
|
|
||||||
std::string ConfigFile;
|
|
||||||
|
|
||||||
public:
|
|
||||||
int ProcessConfigFileInput();
|
|
||||||
|
|
||||||
void addTotalMods() { TotalMods++; }
|
|
||||||
|
|
||||||
InputOutputStats();
|
|
||||||
~InputOutputStats();
|
|
||||||
|
|
||||||
} InputOutputStats_c;
|
|
||||||
#endif
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This so is from libconfig-1.0.1, a library released under the LGPL (I think I'm suppossed to mention that, but I haven't and don't plan to read the thing). I downloaded it from http://www.hyperrealm.com/. You can too.
|
|
||||||
|
|
||||||
Compiling it was a less than pleasant experience on both unix and windows. Instead I offer the libraries, static and linked. Obviously unlike DLLs in windows, them working isn't a good bet. Cross your fingers, make sure you're not on an old Sun workstation, and if you do end up having to compile it yourself, download the code and pray the makefile works.
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
/* ----------------------------------------------------------------------------
|
|
||||||
libconfig - A structured configuration file parsing library
|
|
||||||
Copyright (C) 2005 Mark A Lindner
|
|
||||||
|
|
||||||
This file is part of libconfig.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public License
|
|
||||||
as published by the Free Software Foundation; either version 2.1 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __libconfig_h
|
|
||||||
#define __libconfig_h
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
||||||
#if defined(DLL_EXPORT) || defined(LIBCONFIG_EXPORTS)
|
|
||||||
#define LIBCONFIG_API __declspec(dllexport)
|
|
||||||
#else // ! DLL_EXPORT
|
|
||||||
#define LIBCONFIG_API __declspec(dllimport)
|
|
||||||
#endif // DLL_EXPORT
|
|
||||||
#else // ! WIN32
|
|
||||||
#define LIBCONFIG_API
|
|
||||||
#endif // WIN32
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define CONFIG_TYPE_NONE 0
|
|
||||||
#define CONFIG_TYPE_GROUP 1
|
|
||||||
#define CONFIG_TYPE_INT 2
|
|
||||||
#define CONFIG_TYPE_FLOAT 3
|
|
||||||
#define CONFIG_TYPE_STRING 4
|
|
||||||
#define CONFIG_TYPE_BOOL 5
|
|
||||||
#define CONFIG_TYPE_ARRAY 6
|
|
||||||
#define CONFIG_TYPE_LIST 7
|
|
||||||
|
|
||||||
#define CONFIG_FORMAT_DEFAULT 0
|
|
||||||
#define CONFIG_FORMAT_HEX 1
|
|
||||||
|
|
||||||
#define CONFIG_TRUE (1)
|
|
||||||
#define CONFIG_FALSE (0)
|
|
||||||
|
|
||||||
typedef union config_value_t
|
|
||||||
{
|
|
||||||
long ival;
|
|
||||||
double fval;
|
|
||||||
char *sval;
|
|
||||||
int bval;
|
|
||||||
struct config_list_t *list;
|
|
||||||
} config_value_t;
|
|
||||||
|
|
||||||
typedef struct config_setting_t
|
|
||||||
{
|
|
||||||
char *name;
|
|
||||||
int type;
|
|
||||||
int format;
|
|
||||||
config_value_t value;
|
|
||||||
struct config_setting_t *parent;
|
|
||||||
struct config_t *config;
|
|
||||||
void *hook;
|
|
||||||
} config_setting_t;
|
|
||||||
|
|
||||||
typedef struct config_list_t
|
|
||||||
{
|
|
||||||
unsigned int length;
|
|
||||||
unsigned int capacity;
|
|
||||||
config_setting_t **elements;
|
|
||||||
} config_list_t;
|
|
||||||
|
|
||||||
typedef struct config_t
|
|
||||||
{
|
|
||||||
config_setting_t *root;
|
|
||||||
void (*destructor)(void *);
|
|
||||||
const char *error_text;
|
|
||||||
int error_line;
|
|
||||||
} config_t;
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_read(config_t *config, FILE *stream);
|
|
||||||
extern LIBCONFIG_API void config_write(const config_t *config, FILE *stream);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_read_file(config_t *config,
|
|
||||||
const char *filename);
|
|
||||||
extern LIBCONFIG_API int config_write_file(config_t *config,
|
|
||||||
const char *filename);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API void config_set_destructor(config_t *config,
|
|
||||||
void (*destructor)(void *));
|
|
||||||
|
|
||||||
extern LIBCONFIG_API void config_init(config_t *config);
|
|
||||||
extern LIBCONFIG_API void config_destroy(config_t *config);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API long config_setting_get_int(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API double config_setting_get_float(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API int config_setting_get_bool(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API const char *config_setting_get_string(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_setting_set_int(config_setting_t *setting,
|
|
||||||
long value);
|
|
||||||
extern LIBCONFIG_API int config_setting_set_float(config_setting_t *setting,
|
|
||||||
double value);
|
|
||||||
extern LIBCONFIG_API int config_setting_set_bool(config_setting_t *setting,
|
|
||||||
int value);
|
|
||||||
extern LIBCONFIG_API int config_setting_set_string(config_setting_t *setting,
|
|
||||||
const char *value);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_setting_set_format(config_setting_t *setting,
|
|
||||||
int format);
|
|
||||||
extern LIBCONFIG_API int config_setting_get_format(config_setting_t *setting);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API long config_setting_get_int_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
extern LIBCONFIG_API double config_setting_get_float_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
extern LIBCONFIG_API int config_setting_get_bool_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
extern LIBCONFIG_API const char *config_setting_get_string_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_int_elem(
|
|
||||||
config_setting_t *setting, int index, long value);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_float_elem(
|
|
||||||
config_setting_t *setting, int index, double value);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_bool_elem(
|
|
||||||
config_setting_t *setting, int index, int value);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_string_elem(
|
|
||||||
config_setting_t *setting, int index, const char *value);
|
|
||||||
|
|
||||||
#define /* int */ config_setting_type(/* const config_setting_t * */ S) \
|
|
||||||
((S)->type)
|
|
||||||
|
|
||||||
#define /* const char */ config_setting_name(/* const config_setting_t * */ S) \
|
|
||||||
((S)->name)
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_setting_length(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_get_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_get_member(
|
|
||||||
const config_setting_t *setting, const char *name);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_add(
|
|
||||||
config_setting_t *parent, const char *name, int type);
|
|
||||||
extern LIBCONFIG_API int config_setting_remove(config_setting_t *parent,
|
|
||||||
const char *name);
|
|
||||||
extern LIBCONFIG_API void config_setting_set_hook(config_setting_t *setting,
|
|
||||||
void *hook);
|
|
||||||
|
|
||||||
#define config_setting_get_hook(S) ((S)->hook)
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_lookup(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API long config_lookup_int(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
extern LIBCONFIG_API double config_lookup_float(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
extern LIBCONFIG_API int config_lookup_bool(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
extern LIBCONFIG_API const char *config_lookup_string(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
|
|
||||||
#define /* config_setting_t * */ config_root_setting(/* const config_t * */ C) \
|
|
||||||
((C)->root)
|
|
||||||
|
|
||||||
#define /* const char * */ config_error_text(/* const config_t */ C) \
|
|
||||||
((C)->error_text)
|
|
||||||
|
|
||||||
#define /* int */ config_error_line(/* const config_t */ C) \
|
|
||||||
((C)->error_line)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* __libconfig_h */
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This DLL is from libconfig-1.0.1, a library released under the LGPL (I think I'm suppossed to mention that, but I haven't and don't plan to read the thing). I downloaded it from http://www.hyperrealm.com/. You can too.
|
|
||||||
|
|
||||||
Compiling it was a less than pleasant experience on both unix and windows. Instead I offer the libraries, static and linked. Cross your fingers and hope you don't have to compile the library yourself.
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
EXPORTS
|
|
||||||
config_destroy @1
|
|
||||||
config_init @2
|
|
||||||
config_lookup @3
|
|
||||||
config_lookup_bool @4
|
|
||||||
config_lookup_float @5
|
|
||||||
config_lookup_int @6
|
|
||||||
config_lookup_string @7
|
|
||||||
config_read @8
|
|
||||||
config_read_file @9
|
|
||||||
config_set_destructor @10
|
|
||||||
config_setting_add @11
|
|
||||||
config_setting_get_bool @12
|
|
||||||
config_setting_get_bool_elem @13
|
|
||||||
config_setting_get_elem @14
|
|
||||||
config_setting_get_float @15
|
|
||||||
config_setting_get_float_elem @16
|
|
||||||
config_setting_get_format @17
|
|
||||||
config_setting_get_int @18
|
|
||||||
config_setting_get_int_elem @19
|
|
||||||
config_setting_get_member @20
|
|
||||||
config_setting_get_string @21
|
|
||||||
config_setting_get_string_elem @22
|
|
||||||
config_setting_length @23
|
|
||||||
config_setting_remove @24
|
|
||||||
config_setting_set_bool @25
|
|
||||||
config_setting_set_bool_elem @26
|
|
||||||
config_setting_set_float @27
|
|
||||||
config_setting_set_float_elem @28
|
|
||||||
config_setting_set_format @29
|
|
||||||
config_setting_set_hook @30
|
|
||||||
config_setting_set_int @31
|
|
||||||
config_setting_set_int_elem @32
|
|
||||||
config_setting_set_string @33
|
|
||||||
config_setting_set_string_elem @34
|
|
||||||
config_write @35
|
|
||||||
config_write_file @36
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
/* ----------------------------------------------------------------------------
|
|
||||||
libconfig - A structured configuration file parsing library
|
|
||||||
Copyright (C) 2005 Mark A Lindner
|
|
||||||
|
|
||||||
This file is part of libconfig.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public License
|
|
||||||
as published by the Free Software Foundation; either version 2.1 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __libconfig_h
|
|
||||||
#define __libconfig_h
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
||||||
#if defined(DLL_EXPORT) || defined(LIBCONFIG_EXPORTS)
|
|
||||||
#define LIBCONFIG_API __declspec(dllexport)
|
|
||||||
#else // ! DLL_EXPORT
|
|
||||||
#define LIBCONFIG_API __declspec(dllimport)
|
|
||||||
#endif // DLL_EXPORT
|
|
||||||
#else // ! WIN32
|
|
||||||
#define LIBCONFIG_API
|
|
||||||
#endif // WIN32
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define CONFIG_TYPE_NONE 0
|
|
||||||
#define CONFIG_TYPE_GROUP 1
|
|
||||||
#define CONFIG_TYPE_INT 2
|
|
||||||
#define CONFIG_TYPE_FLOAT 3
|
|
||||||
#define CONFIG_TYPE_STRING 4
|
|
||||||
#define CONFIG_TYPE_BOOL 5
|
|
||||||
#define CONFIG_TYPE_ARRAY 6
|
|
||||||
#define CONFIG_TYPE_LIST 7
|
|
||||||
|
|
||||||
#define CONFIG_FORMAT_DEFAULT 0
|
|
||||||
#define CONFIG_FORMAT_HEX 1
|
|
||||||
|
|
||||||
#define CONFIG_TRUE (1)
|
|
||||||
#define CONFIG_FALSE (0)
|
|
||||||
|
|
||||||
typedef union config_value_t
|
|
||||||
{
|
|
||||||
long ival;
|
|
||||||
double fval;
|
|
||||||
char *sval;
|
|
||||||
int bval;
|
|
||||||
struct config_list_t *list;
|
|
||||||
} config_value_t;
|
|
||||||
|
|
||||||
typedef struct config_setting_t
|
|
||||||
{
|
|
||||||
char *name;
|
|
||||||
int type;
|
|
||||||
int format;
|
|
||||||
config_value_t value;
|
|
||||||
struct config_setting_t *parent;
|
|
||||||
struct config_t *config;
|
|
||||||
void *hook;
|
|
||||||
} config_setting_t;
|
|
||||||
|
|
||||||
typedef struct config_list_t
|
|
||||||
{
|
|
||||||
unsigned int length;
|
|
||||||
unsigned int capacity;
|
|
||||||
config_setting_t **elements;
|
|
||||||
} config_list_t;
|
|
||||||
|
|
||||||
typedef struct config_t
|
|
||||||
{
|
|
||||||
config_setting_t *root;
|
|
||||||
void (*destructor)(void *);
|
|
||||||
const char *error_text;
|
|
||||||
int error_line;
|
|
||||||
} config_t;
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_read(config_t *config, FILE *stream);
|
|
||||||
extern LIBCONFIG_API void config_write(const config_t *config, FILE *stream);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_read_file(config_t *config,
|
|
||||||
const char *filename);
|
|
||||||
extern LIBCONFIG_API int config_write_file(config_t *config,
|
|
||||||
const char *filename);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API void config_set_destructor(config_t *config,
|
|
||||||
void (*destructor)(void *));
|
|
||||||
|
|
||||||
extern LIBCONFIG_API void config_init(config_t *config);
|
|
||||||
extern LIBCONFIG_API void config_destroy(config_t *config);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API long config_setting_get_int(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API double config_setting_get_float(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API int config_setting_get_bool(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API const char *config_setting_get_string(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_setting_set_int(config_setting_t *setting,
|
|
||||||
long value);
|
|
||||||
extern LIBCONFIG_API int config_setting_set_float(config_setting_t *setting,
|
|
||||||
double value);
|
|
||||||
extern LIBCONFIG_API int config_setting_set_bool(config_setting_t *setting,
|
|
||||||
int value);
|
|
||||||
extern LIBCONFIG_API int config_setting_set_string(config_setting_t *setting,
|
|
||||||
const char *value);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_setting_set_format(config_setting_t *setting,
|
|
||||||
int format);
|
|
||||||
extern LIBCONFIG_API int config_setting_get_format(config_setting_t *setting);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API long config_setting_get_int_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
extern LIBCONFIG_API double config_setting_get_float_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
extern LIBCONFIG_API int config_setting_get_bool_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
extern LIBCONFIG_API const char *config_setting_get_string_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_int_elem(
|
|
||||||
config_setting_t *setting, int index, long value);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_float_elem(
|
|
||||||
config_setting_t *setting, int index, double value);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_bool_elem(
|
|
||||||
config_setting_t *setting, int index, int value);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_set_string_elem(
|
|
||||||
config_setting_t *setting, int index, const char *value);
|
|
||||||
|
|
||||||
#define /* int */ config_setting_type(/* const config_setting_t * */ S) \
|
|
||||||
((S)->type)
|
|
||||||
|
|
||||||
#define /* const char */ config_setting_name(/* const config_setting_t * */ S) \
|
|
||||||
((S)->name)
|
|
||||||
|
|
||||||
extern LIBCONFIG_API int config_setting_length(
|
|
||||||
const config_setting_t *setting);
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_get_elem(
|
|
||||||
const config_setting_t *setting, int index);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_get_member(
|
|
||||||
const config_setting_t *setting, const char *name);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_setting_add(
|
|
||||||
config_setting_t *parent, const char *name, int type);
|
|
||||||
extern LIBCONFIG_API int config_setting_remove(config_setting_t *parent,
|
|
||||||
const char *name);
|
|
||||||
extern LIBCONFIG_API void config_setting_set_hook(config_setting_t *setting,
|
|
||||||
void *hook);
|
|
||||||
|
|
||||||
#define config_setting_get_hook(S) ((S)->hook)
|
|
||||||
|
|
||||||
extern LIBCONFIG_API config_setting_t *config_lookup(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
|
|
||||||
extern LIBCONFIG_API long config_lookup_int(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
extern LIBCONFIG_API double config_lookup_float(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
extern LIBCONFIG_API int config_lookup_bool(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
extern LIBCONFIG_API const char *config_lookup_string(const config_t *config,
|
|
||||||
const char *path);
|
|
||||||
|
|
||||||
#define /* config_setting_t * */ config_root_setting(/* const config_t * */ C) \
|
|
||||||
((C)->root)
|
|
||||||
|
|
||||||
#define /* const char * */ config_error_text(/* const config_t */ C) \
|
|
||||||
((C)->error_text)
|
|
||||||
|
|
||||||
#define /* int */ config_error_line(/* const config_t */ C) \
|
|
||||||
((C)->error_line)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* __libconfig_h */
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#include "externs.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include "WONnetwk.h"
|
|
||||||
#include "banlist.h"
|
|
||||||
#include "packetry.h"
|
|
||||||
#include "port.h"
|
|
||||||
#include "ModList.h"
|
|
||||||
|
|
||||||
/*** Globals ***/
|
|
||||||
|
|
||||||
//Read extern.h for the reasoning behind this.
|
|
||||||
IPBanList_c * ptrBanlist;
|
|
||||||
PacketManagement_c * ptrSocketClass;
|
|
||||||
ModList_c * ptrMods;
|
|
||||||
|
|
||||||
/*** MAIN ***/
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
|
|
||||||
ptrSocketClass = new PacketManagement(); // keep before WON2ServNetwk
|
|
||||||
ptrMods = new ModList();
|
|
||||||
ptrBanlist = new IPBanList();
|
|
||||||
|
|
||||||
// Parse config files */
|
|
||||||
ptrIO->ProcessConfigFileInput();
|
|
||||||
|
|
||||||
// Parse command line
|
|
||||||
if((argc > 1 && ptrIO->ProcessCommandlineInput(argc, argv) != 0) || ptrSocketClass->StartTheNetwork() != 0) {
|
|
||||||
while(getchar == 27)
|
|
||||||
return(0);
|
|
||||||
//loop
|
|
||||||
}
|
|
||||||
ptrSocketClass->DisableNetwork();
|
|
||||||
delete ptrMods;
|
|
||||||
delete ptrBanlist;
|
|
||||||
delete ptrIO;
|
|
||||||
delete ptrSocketClass;
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
cout << "Hello world!" << endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This small and very old library works like a charm, unlike the thousand or so other command line libraries that wouldn't compile or port or anything. Well that's not entirely true; for some reason I get some sort of linking error in ld when I try to make it a dll, but static linking is probably for the best anyway.
|
|
||||||
|
|
||||||
It's not exactly all inclusive, but it does what I need.
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large.
Load diff
@@ -1,489 +0,0 @@
|
|||||||
// ****************************************************************************
|
|
||||||
// ^FILE: options.h - option parsing classes
|
|
||||||
//
|
|
||||||
// ^DESCRIPTION:
|
|
||||||
// This file defines classes used to parse command-line options.
|
|
||||||
// Options may be parsed from an array of strings, or from any structure
|
|
||||||
// for which a corresponding option-iterator exists.
|
|
||||||
//
|
|
||||||
// ^HISTORY:
|
|
||||||
// 03/06/92 Brad Appleton <bradapp@enteract.com> Created
|
|
||||||
//
|
|
||||||
// 03/23/93 Brad Appleton <bradapp@enteract.com>
|
|
||||||
// - Added OptIstreamIter class
|
|
||||||
//
|
|
||||||
// 03/08/94 Brad Appleton <bradapp@enteract.com>
|
|
||||||
// - Added Options::reset() member function
|
|
||||||
//
|
|
||||||
// 07/31/97 Brad Appleton <bradapp@enteract.com>
|
|
||||||
// - Added PARSE_POS control flag and POSITIONAL return value
|
|
||||||
// ^^**************************************************************************
|
|
||||||
|
|
||||||
#ifndef _options_h
|
|
||||||
#define _options_h
|
|
||||||
|
|
||||||
class ostream;
|
|
||||||
class istream;
|
|
||||||
|
|
||||||
// Abstract class to iterate through options/arguments
|
|
||||||
//
|
|
||||||
class OptIter {
|
|
||||||
public:
|
|
||||||
OptIter(void) {}
|
|
||||||
virtual ~OptIter(void);
|
|
||||||
|
|
||||||
// curr() returns the current item in the iterator without
|
|
||||||
// advancing on to the next item. If we are at the end of items
|
|
||||||
// then NULL is returned.
|
|
||||||
virtual const char *
|
|
||||||
curr(void) = 0;
|
|
||||||
|
|
||||||
// next() advances to the next item.
|
|
||||||
virtual void
|
|
||||||
next(void) = 0;
|
|
||||||
|
|
||||||
// operator() returns the current item in the iterator and then
|
|
||||||
// advances on to the next item. If we are at the end of items
|
|
||||||
// then NULL is returned.
|
|
||||||
virtual const char *
|
|
||||||
operator()(void);
|
|
||||||
} ;
|
|
||||||
|
|
||||||
// Abstract class for a rewindable OptIter
|
|
||||||
//
|
|
||||||
class OptIterRwd : public OptIter {
|
|
||||||
public:
|
|
||||||
OptIterRwd(void);
|
|
||||||
|
|
||||||
virtual ~OptIterRwd(void);
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
curr(void) = 0;
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
next(void) = 0;
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
operator()(void) = 0;
|
|
||||||
|
|
||||||
// rewind() resets the "current-element" to the first one in the "list"
|
|
||||||
virtual void
|
|
||||||
rewind(void) = 0;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
// Class to iterate through an array of tokens. The array may be terminated
|
|
||||||
// by NULL or a count containing the number of tokens may be given.
|
|
||||||
//
|
|
||||||
class OptArgvIter : public OptIterRwd {
|
|
||||||
private:
|
|
||||||
int ndx; // index of current arg
|
|
||||||
int ac; // arg count
|
|
||||||
const char * const * av; // arg vector
|
|
||||||
|
|
||||||
public:
|
|
||||||
OptArgvIter(const char * const argv[])
|
|
||||||
: ndx(0), ac(-1), av(argv) {}
|
|
||||||
|
|
||||||
OptArgvIter(int argc, const char * const argv[])
|
|
||||||
: ndx(0), ac(argc), av(argv) {}
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~OptArgvIter(void);
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
curr(void);
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
next(void);
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
operator()(void);
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
rewind(void);
|
|
||||||
|
|
||||||
// index returns the current index to use for argv[]
|
|
||||||
int index(void) { return ndx; }
|
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
// Class to iterate through a string containing delimiter-separated tokens
|
|
||||||
//
|
|
||||||
class OptStrTokIter : public OptIterRwd {
|
|
||||||
private:
|
|
||||||
unsigned len; // length of token-string
|
|
||||||
const char * str; // the token-string
|
|
||||||
const char * seps; // delimiter-set (separator-characters)
|
|
||||||
const char * cur; // current token
|
|
||||||
char * tokstr; // our copy of the token-string
|
|
||||||
|
|
||||||
static const char * default_delims; // default delimiters = whitespace
|
|
||||||
|
|
||||||
public:
|
|
||||||
OptStrTokIter(const char * tokens, const char * delimiters =0);
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~OptStrTokIter(void);
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
curr(void);
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
next(void);
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
operator()(void);
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
rewind(void);
|
|
||||||
|
|
||||||
// delimiters() with NO arguments returns the current set of delimiters,
|
|
||||||
// If an argument is given then it is used as the new set of delimiters.
|
|
||||||
const char *
|
|
||||||
delimiters(void) { return seps; }
|
|
||||||
|
|
||||||
void
|
|
||||||
delimiters(const char * delims) {
|
|
||||||
seps = (delims) ? delims : default_delims ;
|
|
||||||
}
|
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
// OptIstreamIter is a class for iterating over arguments that come
|
|
||||||
// from an input stream. Each line of the input stream is considered
|
|
||||||
// to be a set of white-space separated tokens. If the the first
|
|
||||||
// non-white character on a line is '#' ('!' for VMS systems) then
|
|
||||||
// the line is considered a comment and is ignored.
|
|
||||||
//
|
|
||||||
// *Note:: If a line is more than 1022 characters in length then we
|
|
||||||
// treat it as if it were several lines of length 1022 or less.
|
|
||||||
//
|
|
||||||
// *Note:: The string tokens returned by this iterator are pointers
|
|
||||||
// to temporary buffers which may not necessarily stick around
|
|
||||||
// for too long after the call to curr() or operator(), hence
|
|
||||||
// if you need the string value to persist - you will need to
|
|
||||||
// make a copy.
|
|
||||||
//
|
|
||||||
class OptIstreamIter : public OptIter {
|
|
||||||
private:
|
|
||||||
istream & is ;
|
|
||||||
OptStrTokIter * tok_iter ;
|
|
||||||
|
|
||||||
void
|
|
||||||
fill(void);
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const unsigned MAX_LINE_LEN ;
|
|
||||||
|
|
||||||
OptIstreamIter(istream & input);
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~OptIstreamIter(void);
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
curr(void);
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
next(void);
|
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
operator()(void);
|
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
// Now we are ready to define a class to declare and parse command-options
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// CLASS
|
|
||||||
// =====
|
|
||||||
// Options -- parse command-line options
|
|
||||||
//
|
|
||||||
// SYNOPSIS
|
|
||||||
// ========
|
|
||||||
// #include <options.h>
|
|
||||||
//
|
|
||||||
// Options opts(cmdname, optv);
|
|
||||||
// char cmdname[], *optv[];
|
|
||||||
//
|
|
||||||
// DESCRIPTION
|
|
||||||
// ===========
|
|
||||||
// The Options constructor expects a command-name (usually argv[0]) and
|
|
||||||
// a pointer to an array of strings. The last element in this array MUST
|
|
||||||
// be NULL. Each non-NULL string in the array must have the following format:
|
|
||||||
//
|
|
||||||
// The 1st character must be the option-name ('c' for a -c option).
|
|
||||||
//
|
|
||||||
// The 2nd character must be one of '|', '?', ':', '*', or '+'.
|
|
||||||
// '|' -- indicates that the option takes NO argument;
|
|
||||||
// '?' -- indicates that the option takes an OPTIONAL argument;
|
|
||||||
// ':' -- indicates that the option takes a REQUIRED argument;
|
|
||||||
// '*' -- indicates that the option takes 0 or more arguments;
|
|
||||||
// '+' -- indicates that the option takes 1 or more arguments;
|
|
||||||
//
|
|
||||||
// The remainder of the string must be the long-option name.
|
|
||||||
//
|
|
||||||
// If desired, the long-option name may be followed by one or more
|
|
||||||
// spaces and then by the name of the option value. This name will
|
|
||||||
// be used when printing usage messages. If the option-value-name
|
|
||||||
// is not given then the string "<value>" will be used in usage
|
|
||||||
// messages.
|
|
||||||
//
|
|
||||||
// One may use a space to indicate that a particular option does not
|
|
||||||
// have a corresponding long-option. For example, "c: " (or "c:")
|
|
||||||
// means the -c option takes a value & has NO corresponding long-option.
|
|
||||||
//
|
|
||||||
// To specify a long-option that has no corresponding single-character
|
|
||||||
// option is a bit trickier: Options::operator() still needs an "option-
|
|
||||||
// character" to return when that option is matched. One may use a whitespace
|
|
||||||
// character or a non-printable character as the single-character option
|
|
||||||
// in such a case. (hence " |hello" would only match "--hello").
|
|
||||||
//
|
|
||||||
// EXCEPTIONS TO THE ABOVE:
|
|
||||||
// ------------------------
|
|
||||||
// If the 1st character of the string is '-', then the rest of the
|
|
||||||
// string must correspond to the above format, and the option is
|
|
||||||
// considered to be a hidden-option. This means it will be parsed
|
|
||||||
// when actually matching options from the command-line, but will
|
|
||||||
// NOT show-up if a usage message is printed using the usage() member
|
|
||||||
// function. Such an example might be "-h|hidden". If you want to
|
|
||||||
// use any "dummy" options (options that are not parsed, but that
|
|
||||||
// to show up in the usage message), you can specify them along with
|
|
||||||
// any positional parameters to the usage() member function.
|
|
||||||
//
|
|
||||||
// If the 2nd character of the string is '\0' then it is assumed
|
|
||||||
// that there is no corresponding long-option and that the option
|
|
||||||
// takes no argument (hence "f", and "f| " are equivalent).
|
|
||||||
//
|
|
||||||
// Examples:
|
|
||||||
// const char * optv[] = {
|
|
||||||
// "c:count <number>",
|
|
||||||
// "s?str <string>",
|
|
||||||
// "x",
|
|
||||||
// " |hello",
|
|
||||||
// "g+groups <newsgroup>",
|
|
||||||
// NULL
|
|
||||||
// } ;
|
|
||||||
//
|
|
||||||
// optv[] now corresponds to the following:
|
|
||||||
//
|
|
||||||
// usage: cmdname [-c|--count <number>] [-s|--str [<string>]]
|
|
||||||
// [-x] [--hello] [-g|--groups <newsgroup> ...]
|
|
||||||
//
|
|
||||||
// Long-option names are matched case-insensitive and only a unique prefix
|
|
||||||
// of the name needs to be specified.
|
|
||||||
//
|
|
||||||
// Option-name characters are case-sensitive!
|
|
||||||
//
|
|
||||||
// CAVEAT
|
|
||||||
// ======
|
|
||||||
// Because of the way in which multi-valued options and options with optional
|
|
||||||
// values are handled, it is NOT possible to supply a value to an option in
|
|
||||||
// a separate argument (different argv[] element) if the value is OPTIONAL
|
|
||||||
// and begins with a '-'. What this means is that if an option "-s" takes an
|
|
||||||
// optional value value and you wish to supply a value of "-foo" then you must
|
|
||||||
// specify this on the command-line as "-s-foo" instead of "-s -foo" because
|
|
||||||
// "-s -foo" will be considered to be two separate sets of options.
|
|
||||||
//
|
|
||||||
// A multi-valued option is terminated by another option or by the end-of
|
|
||||||
// options. The following are all equivalent (if "-l" is a multi-valued
|
|
||||||
// option and "-x" is an option that takes no value):
|
|
||||||
//
|
|
||||||
// cmdname -x -l item1 item2 item3 -- arg1 arg2 arg3
|
|
||||||
// cmdname -x -litem1 -litem2 -litem3 -- arg1 arg2 arg3
|
|
||||||
// cmdname -l item1 item2 item3 -x arg1 arg2 arg3
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// EXAMPLE
|
|
||||||
// =======
|
|
||||||
// #include <options.h>
|
|
||||||
//
|
|
||||||
// static const char * optv[] = {
|
|
||||||
// "H|help",
|
|
||||||
// "c:count <number>",
|
|
||||||
// "s?str <string>",
|
|
||||||
// "x",
|
|
||||||
// " |hello",
|
|
||||||
// "g+groups <newsgroup>",
|
|
||||||
// NULL
|
|
||||||
// } ;
|
|
||||||
//
|
|
||||||
// main(int argc, char * argv[]) {
|
|
||||||
// int optchar;
|
|
||||||
// const char * optarg;
|
|
||||||
// const char * str = "default_string";
|
|
||||||
// int count = 0, xflag = 0, hello = 0;
|
|
||||||
// int errors = 0, ngroups = 0;
|
|
||||||
//
|
|
||||||
// Options opts(*argv, optv);
|
|
||||||
// OptArgvIter iter(--argc, ++argv);
|
|
||||||
//
|
|
||||||
// while( optchar = opts(iter, optarg) ) {
|
|
||||||
// switch (optchar) {
|
|
||||||
// case 'H' :
|
|
||||||
// opts.usage(cout, "files ...");
|
|
||||||
// exit(0);
|
|
||||||
// break;
|
|
||||||
// case 'g' :
|
|
||||||
// ++ngroups; break; // the groupname is in "optarg"
|
|
||||||
// case 's' :
|
|
||||||
// str = optarg; break;
|
|
||||||
// case 'x' :
|
|
||||||
// ++xflag; break;
|
|
||||||
// case ' ' :
|
|
||||||
// ++hello; break;
|
|
||||||
// case 'c' :
|
|
||||||
// if (optarg == NULL) ++errors;
|
|
||||||
// else count = (int) atol(optarg);
|
|
||||||
// break;
|
|
||||||
// default : ++errors; break;
|
|
||||||
// } //switch
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (errors || (iter.index() == argc)) {
|
|
||||||
// if (! errors) {
|
|
||||||
// cerr << opts.name() << ": no filenames given." << endl ;
|
|
||||||
// }
|
|
||||||
// opts.usage(cerr, "files ...");
|
|
||||||
// exit(1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// cout << "xflag=" << ((xflag) ? "ON" : "OFF") << endl
|
|
||||||
// << "hello=" << ((hello) ? "YES" : "NO") << endl
|
|
||||||
// << "count=" << count << endl
|
|
||||||
// << "str=\"" << ((str) ? str : "No value given!") << "\"" << endl
|
|
||||||
// << "ngroups=" << ngroups << endl ;
|
|
||||||
//
|
|
||||||
// if (iter.index() < argc) {
|
|
||||||
// cout << "files=" ;
|
|
||||||
// for (int i = iter.index() ; i < argc ; i++) {
|
|
||||||
// cout << "\"" << argv[i] << "\" " ;
|
|
||||||
// }
|
|
||||||
// cout << endl ;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
class Options {
|
|
||||||
private:
|
|
||||||
unsigned explicit_end : 1; // were we terminated because of "--"?
|
|
||||||
unsigned optctrls : 7; // control settings (a set of OptCtrl masks)
|
|
||||||
const char * const * optvec; // vector of option-specifications (last=NULL)
|
|
||||||
const char * nextchar; // next option-character to process
|
|
||||||
const char * listopt; // last list-option we matched
|
|
||||||
const char * cmdname; // name of the command
|
|
||||||
|
|
||||||
void
|
|
||||||
check_syntax(void) const;
|
|
||||||
|
|
||||||
const char *
|
|
||||||
match_opt(char opt, int ignore_case =0) const;
|
|
||||||
|
|
||||||
const char *
|
|
||||||
match_longopt(const char * opt, int len, int & ambiguous) const;
|
|
||||||
|
|
||||||
int
|
|
||||||
parse_opt(OptIter & iter, const char * & optarg);
|
|
||||||
|
|
||||||
int
|
|
||||||
parse_longopt(OptIter & iter, const char * & optarg);
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum OptCtrl {
|
|
||||||
DEFAULT = 0x00, // Default setting
|
|
||||||
ANYCASE = 0x01, // Ignore case when matching short-options
|
|
||||||
QUIET = 0x02, // Dont print error messages
|
|
||||||
PLUS = 0x04, // Allow "+" as a long-option prefix
|
|
||||||
SHORT_ONLY = 0x08, // Dont accept long-options
|
|
||||||
LONG_ONLY = 0x10, // Dont accept short-options
|
|
||||||
// (also allows "-" as a long-option prefix).
|
|
||||||
NOGUESSING = 0x20, // Normally, when we see a short (long) option
|
|
||||||
// on the command line that doesnt match any
|
|
||||||
// known short (long) options, then we try to
|
|
||||||
// "guess" by seeing if it will match any known
|
|
||||||
// long (short) option. Setting this mask prevents
|
|
||||||
// this "guessing" from occurring.
|
|
||||||
PARSE_POS = 0x40 // By default, Options will not present positional
|
|
||||||
// command-line arguments to the user and will
|
|
||||||
// instead stop parsing when the first positonal
|
|
||||||
// argument has been encountered. If this flag
|
|
||||||
// is given, Options will present positional
|
|
||||||
// arguments to the user with a return code of
|
|
||||||
// POSITIONAL; ENDOPTS will be returned only
|
|
||||||
// when the end of the argument list is reached.
|
|
||||||
} ;
|
|
||||||
|
|
||||||
// Error return values for operator()
|
|
||||||
//
|
|
||||||
enum OptRC {
|
|
||||||
ENDOPTS = 0,
|
|
||||||
BADCHAR = -1,
|
|
||||||
BADKWD = -2,
|
|
||||||
AMBIGUOUS = -3,
|
|
||||||
POSITIONAL = -4
|
|
||||||
} ;
|
|
||||||
|
|
||||||
Options(const char * name, const char * const optv[]);
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~Options(void);
|
|
||||||
|
|
||||||
// name() returns the command name
|
|
||||||
const char *
|
|
||||||
name(void) const { return cmdname; }
|
|
||||||
|
|
||||||
// ctrls() (with no arguments) returns the existing control settings
|
|
||||||
unsigned
|
|
||||||
ctrls(void) const { return optctrls; }
|
|
||||||
|
|
||||||
// ctrls() (with 1 argument) sets new control settings
|
|
||||||
void
|
|
||||||
ctrls(unsigned newctrls) { optctrls = newctrls; }
|
|
||||||
|
|
||||||
// reset for another pass to parse for options
|
|
||||||
void
|
|
||||||
reset(void) { nextchar = listopt = NULL; }
|
|
||||||
|
|
||||||
// usage() prints options usage (followed by any positional arguments
|
|
||||||
// listed in the parameter "positionals") on the given outstream
|
|
||||||
void
|
|
||||||
usage(ostream & os, const char * positionals) const ;
|
|
||||||
|
|
||||||
// operator() iterates through the arguments as necessary (using the
|
|
||||||
// given iterator) and returns the character value of the option
|
|
||||||
// (or long-option) that it matched. If the option has a value
|
|
||||||
// then the value given may be found in optarg (otherwise optarg
|
|
||||||
// will be NULL).
|
|
||||||
//
|
|
||||||
// 0 is returned upon end-of-options. At this point, "iter" may
|
|
||||||
// be used to process any remaining positional parameters. If the
|
|
||||||
// PARSE_POS control-flag is set then 0 is returned only when all
|
|
||||||
// arguments in "iter" have been exhausted.
|
|
||||||
//
|
|
||||||
// If an invalid option is found then BADCHAR is returned and *optarg
|
|
||||||
// is the unrecognized option character.
|
|
||||||
//
|
|
||||||
// If an invalid long-option is found then BADKWD is returned and optarg
|
|
||||||
// points to the bad long-option.
|
|
||||||
//
|
|
||||||
// If an ambiguous long-option is found then AMBIGUOUS is returned and
|
|
||||||
// optarg points to the ambiguous long-option.
|
|
||||||
//
|
|
||||||
// If the PARSE_POS control-flag is set then POSITIONAL is returned
|
|
||||||
// when a positional argument is encountered and optarg points to
|
|
||||||
// the positonal argument (and "iter" is advanced to the next argument
|
|
||||||
// in the iterator).
|
|
||||||
//
|
|
||||||
// Unless Options::QUIET is used, missing option-arguments and
|
|
||||||
// invalid options (and the like) will automatically cause error
|
|
||||||
// messages to be issued to cerr.
|
|
||||||
int
|
|
||||||
operator()(OptIter & iter, const char * & optarg) ;
|
|
||||||
|
|
||||||
// Call this member function after operator() has returned 0
|
|
||||||
// if you want to know whether or not options were explicitly
|
|
||||||
// terminated because "--" appeared on the command-line.
|
|
||||||
//
|
|
||||||
int
|
|
||||||
explicit_endopts() const { return explicit_end; }
|
|
||||||
} ;
|
|
||||||
|
|
||||||
#endif /* _options_h */
|
|
||||||
@@ -1,238 +0,0 @@
|
|||||||
#include "packetry.h"
|
|
||||||
|
|
||||||
/******** Constructor/Destructor ********/
|
|
||||||
|
|
||||||
PacketManagement::PacketManagement() {
|
|
||||||
|
|
||||||
/* socket stuff */
|
|
||||||
sizeofClientAddress = sizeof(CurrentClientSockAddress);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
PacketManagement::~PacketManagement() {
|
|
||||||
|
|
||||||
//DisableNetwork(); //we have to init it separately, same for destroy.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******** The Only Public Function ********/
|
|
||||||
|
|
||||||
/* DESCRIPTION: ProcessInput
|
|
||||||
//
|
|
||||||
// This function is the root function in our class. On each call it
|
|
||||||
// blocks and waits for a packet.
|
|
||||||
*/
|
|
||||||
void PacketManagement::ProcessInput() {
|
|
||||||
|
|
||||||
/* Let's handle one packet, shall we? */
|
|
||||||
|
|
||||||
CurrentNumberOfBytesReceived = recvfrom(socket_GLOBAL, (char *)packetbuffer, MAX_PACKET_LENGTH, 0, (struct sockaddr *)&CurrentClientSockAddress, &sizeofClientAddress);
|
|
||||||
pthread_testcancel();
|
|
||||||
|
|
||||||
if(CurrentNumberOfBytesReceived == SOCKET_ERROR) {
|
|
||||||
ptrIO->inc___FailedPacketSends();
|
|
||||||
if(WSAGetLastError() != WSAENETRESET && WSAGetLastError() != WSAECONNRESET) {
|
|
||||||
PRINTERROR; //CONN/NETRESET mean a message we sent failed. Regrettable, but not uncommon, so we don't need to know about it. CONNRESET seems to be a BUG in the Windows API though.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(CurrentNumberOfBytesReceived > 0) {
|
|
||||||
ptrIO->UpdateBytesReceived(CurrentNumberOfBytesReceived);
|
|
||||||
ptrIO->inc___TotalPacketsReceived();
|
|
||||||
packetbuffer[CurrentNumberOfBytesReceived] = '\0';
|
|
||||||
ptrIO->OutputFileData(4, "PACKET received, size:%i\n", CurrentNumberOfBytesReceived);
|
|
||||||
ptrIO->OutputFileDataRaw(4, packetbuffer, CurrentNumberOfBytesReceived);
|
|
||||||
ptrIO->OutputFileData(4, "\n");
|
|
||||||
ProcessPacket();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: ProcessPacket
|
|
||||||
//
|
|
||||||
// This function makes heavy use of the variables packetbuffer and
|
|
||||||
// ClientAddress.
|
|
||||||
*/
|
|
||||||
void PacketManagement::ProcessPacket() {
|
|
||||||
|
|
||||||
#define A2M_GETMODLIST 'n'
|
|
||||||
#define A2M_SELECTMOD 'p'
|
|
||||||
|
|
||||||
//Before we do anything, drop the packet if we don't like the sender
|
|
||||||
if((ptrBanlist->IsSockaddrBanned(CurrentClientSockAddress))) {
|
|
||||||
Printf("Rejected packet from blocked address (in hex) %X.", CurrentClientSockAddress.sin_addr.s_addr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch(packetbuffer[0]) {
|
|
||||||
|
|
||||||
case A2M_SELECTMOD:
|
|
||||||
ptrIO->IN_x_ProcessModRequest);
|
|
||||||
printf("Mod request received.");
|
|
||||||
StripOutUnwantedNullsInPacket(packetbuffer);
|
|
||||||
IN_x_ProcessModRequest();
|
|
||||||
break;
|
|
||||||
case A2M_GETMODLIST:
|
|
||||||
ptrIO->IN_x_ProcessModListRequest();
|
|
||||||
Printf("Mod list request received.");
|
|
||||||
IN_x_ProcessModListRequest();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("Unknown packet recieved");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: StripOutUnwantedNullsInPacket
|
|
||||||
//
|
|
||||||
// To be called immediately after receiving a function that would be hindered
|
|
||||||
// by nulls. In processing, very few packets actually care about returns or
|
|
||||||
// nulls, so we can save ourselves some hassle later on by removing all but
|
|
||||||
// the last one.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void PacketManagement::StripOutUnwantedNullsInPacket(char* packet) {
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
int j = 0;
|
|
||||||
|
|
||||||
for(; i < CurrentNumberOfBytesReceived; i++) {
|
|
||||||
if(packet[i] == '\0' || packet[i] == '\r' || packet[i] == '\n') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
packet[j] = tolower(packet[i]);
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
packet[j] = '\0';
|
|
||||||
CurrentNumberOfBytesReceived = j;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: GetKeyPairValue
|
|
||||||
//
|
|
||||||
// Half-Life seems to be a bit lenient in how these things can be formatted.
|
|
||||||
// Rather than force an order, it just seems to look for the key and assume
|
|
||||||
// the next string is the value. We follow suit. Note that there are possible
|
|
||||||
// problems here; malicious tampering isn't a huge issue. However, keys in
|
|
||||||
// server descriptions can be if they're not placed at the end (they always
|
|
||||||
// should be). Overall, this isn't complicated.
|
|
||||||
//
|
|
||||||
// Returns a pointer to a string. The string contains only a null if we
|
|
||||||
// failed to find the token. To do: make more like the next two functions.
|
|
||||||
*/
|
|
||||||
char* PacketManagement::GetKeyPairValue(const char* string, const char* value) {
|
|
||||||
|
|
||||||
//At the moment only one thread ever uses this, so there is no need to mess
|
|
||||||
//with making it threadable.
|
|
||||||
static char returnValue[64];
|
|
||||||
int i = 0;
|
|
||||||
char* ptr;
|
|
||||||
|
|
||||||
if(strlen(value) > 20) {
|
|
||||||
// There are no tokens that long. If we get one that long, just fail and
|
|
||||||
// leave the programmer scratching his head as I'm not mallocing in this
|
|
||||||
// function.
|
|
||||||
returnValue[0] = '\0';
|
|
||||||
return(returnValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Surround our token with backslashes. That's how they appear in packets,
|
|
||||||
// and that way we won't trigger a map or something called 'version'.
|
|
||||||
sprintf(returnValue, "\\%s\\", value);
|
|
||||||
|
|
||||||
ptr = strstr(string, value);
|
|
||||||
if(ptr == NULL) { returnValue[0] = '\0'; }
|
|
||||||
else {
|
|
||||||
// If we are here, we found this token. The next token should be what we
|
|
||||||
// return. Now, not EVERY token is encased in slashes (the last isn't),
|
|
||||||
// and returns might be desired. Who knows. So we only break for nulls
|
|
||||||
// and slashes. And remember, all input is evil.
|
|
||||||
|
|
||||||
//First let's jump past this token we found...
|
|
||||||
ptr += strlen(value)+1;
|
|
||||||
|
|
||||||
//now let's go until we hit something we should break for.
|
|
||||||
while(*ptr != '\0' && *ptr != '\\' && i < 63) {
|
|
||||||
returnValue[i] = *ptr;
|
|
||||||
i++;
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
//This tacks on a null. It also leaves us with an empty string if we
|
|
||||||
//had someone send us a funny packet.
|
|
||||||
returnValue[i] = '\0';
|
|
||||||
}
|
|
||||||
return(returnValue);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: GetNextToken
|
|
||||||
//
|
|
||||||
// Takes a string and returns tokens. The second argument is where the copied
|
|
||||||
// tokens will be placed (instead of a static variable), the third is the max
|
|
||||||
// length. And the fourth is what we are looking for. The fifth is our
|
|
||||||
// packet's length.
|
|
||||||
*/
|
|
||||||
unsigned int PacketManagement::GetNextToken(const char* string, char* retval, const unsigned int length, const unsigned int packlen) {
|
|
||||||
return(GetNextToken(string, retval, length, packlen, '\0'));
|
|
||||||
}
|
|
||||||
unsigned int PacketManagement::GetNextToken(const char* string, char* retval, const unsigned int length, const unsigned int packlen, const char delim) {
|
|
||||||
|
|
||||||
unsigned int i = 0;
|
|
||||||
|
|
||||||
while(string[i] != delim && i < length && i < packlen) {
|
|
||||||
retval[i] = string[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: StartTheNetwork
|
|
||||||
//
|
|
||||||
// Copy and pasted from other programs I've done. Does that annoying
|
|
||||||
// behind-the-scenes stuff to get the network started.
|
|
||||||
//
|
|
||||||
// Is now a public function. We have to start the NETWORKING class before the
|
|
||||||
// INPUT class, but until we've started the input class we can't find out
|
|
||||||
// what port we should run on.
|
|
||||||
*/
|
|
||||||
int PacketManagement::StartTheNetwork() {
|
|
||||||
|
|
||||||
//remember, we have socket_GLOBAL just waiting to be initialized
|
|
||||||
struct sockaddr_in ServerAddress;
|
|
||||||
|
|
||||||
DoWindowsNetThing();
|
|
||||||
|
|
||||||
socket_GLOBAL = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
|
||||||
if(socket_GLOBAL == (signed)INVALID_SOCKET) {
|
|
||||||
printf("Error invalid socket");
|
|
||||||
DisableNetwork();
|
|
||||||
return(254);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&ServerAddress, 0, sizeof(ServerAddress));
|
|
||||||
|
|
||||||
ServerAddress.sin_family = AF_INET;
|
|
||||||
ServerAddress.sin_port = htons(ptrIO->GetPort()); //port=Global
|
|
||||||
ServerAddress.sin_addr.s_addr=INADDR_ANY; //I hope this doesn't cause problems
|
|
||||||
|
|
||||||
if(bind(socket_GLOBAL, (struct sockaddr *)&ServerAddress, sizeof(ServerAddress))==SOCKET_ERROR) {
|
|
||||||
printf("Cant bind to local acdress");
|
|
||||||
DisableNetwork();
|
|
||||||
return(253);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Yep, for UDP, that's it.
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PacketManagement::DisableNetwork() {
|
|
||||||
|
|
||||||
if(socket_GLOBAL != (signed)INVALID_SOCKET) {
|
|
||||||
|
|
||||||
shutdown(socket_GLOBAL, 2);
|
|
||||||
close(socket_GLOBAL);
|
|
||||||
socket_GLOBAL = INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
WSACleanup(); //We can call this repeatedly w/o issue.
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
//
|
|
||||||
// This 'class' is the meat of the code. There should only ever be one
|
|
||||||
// instance of this class ever, and only one thing for main() to call.
|
|
||||||
//
|
|
||||||
// This class acts as the parent of both the input and output classes.
|
|
||||||
// All that is here belongs to them too.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__PACKETRY_H_
|
|
||||||
#define __MASTER__SERVER__PACKETRY_H_
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include "port.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include "externs.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include "WONnetwk.h"
|
|
||||||
#include "ModList.h"
|
|
||||||
|
|
||||||
#ifndef MAX_PACKET_LENGTH
|
|
||||||
#define MAX_PACKET_LENGTH 1400
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//#define DEBUG_NOFILTER
|
|
||||||
/*** The class ***/
|
|
||||||
|
|
||||||
// There can only be one.
|
|
||||||
|
|
||||||
typedef class PacketManagement {
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
signed int socket_GLOBAL;
|
|
||||||
|
|
||||||
/* packet related vars */
|
|
||||||
|
|
||||||
signed int CurrentNumberOfBytesReceived;
|
|
||||||
struct sockaddr_in CurrentClientSockAddress;
|
|
||||||
socklen_t sizeofClientAddress;
|
|
||||||
char packetbuffer[MAX_PACKET_LENGTH+1]; //One char of wiggle room, hehe
|
|
||||||
|
|
||||||
/*** Functions ***/
|
|
||||||
|
|
||||||
/* Packet handling related */
|
|
||||||
|
|
||||||
void ProcessPacket();
|
|
||||||
void StripOutUnwantedNullsInPacket(char*);
|
|
||||||
char* GetKeyPairValue(const char*, const char*);
|
|
||||||
unsigned int GetNextToken(const char*, char*, const unsigned int, const unsigned int, const char);
|
|
||||||
unsigned int GetNextToken(const char*, char*, const unsigned int, const unsigned int);
|
|
||||||
|
|
||||||
// When sending or receiving data, '\0', '\n', and '\r' are removed. Half-Life
|
|
||||||
// does it, HL expects us to do it when it sends us something, we do it.
|
|
||||||
|
|
||||||
int IN_x_ProcessModRequest();
|
|
||||||
void OUT_y_SendModRequest(struct sockaddr_in, const char *);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
PacketManagement();
|
|
||||||
~PacketManagement();
|
|
||||||
|
|
||||||
void OUT_SendSpecificReply(char*, unsigned int, struct sockaddr_in);
|
|
||||||
void ProcessInput();
|
|
||||||
|
|
||||||
int StartTheNetwork();
|
|
||||||
void DisableNetwork();
|
|
||||||
|
|
||||||
} PacketManagement_c;
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#include "packetry.h"
|
|
||||||
|
|
||||||
/* DESCRIPTION: IN_x_ProcessModRequest
|
|
||||||
//
|
|
||||||
// Surprisigly similar to requesting server lists. This one however
|
|
||||||
// requests a MOD listing.
|
|
||||||
*/
|
|
||||||
int PacketManagement::IN_x_ProcessModRequest() {
|
|
||||||
|
|
||||||
OUT_y_SendModRequest(CurrentClientSockAddress, packetbuffer+1);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
#include "packetry.h"
|
|
||||||
|
|
||||||
/* Everything in this file refers to the sending of specific packets. This
|
|
||||||
** file, pkt_IN.cc, and packetry.cc all make up the master server class.
|
|
||||||
** For better organization, the three are separated into smaller files.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: OUT_d_SendServerList
|
|
||||||
//
|
|
||||||
// Assumed identical to OUT_serverlist_f but wothout the first few bytes
|
|
||||||
// acting as a placeholder. UNPROVEN ASSUMPTION.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void PacketManagement::OUT_d_SendServerList(struct sockaddr_in DestinationAddress) {
|
|
||||||
|
|
||||||
unsigned int packetlen = 6;
|
|
||||||
unsigned long int position = 0; //0 is the default, but we must pass by reference
|
|
||||||
strcpy(packetbuffer, "\xff\xff\xff\xff" "o\n");
|
|
||||||
packetlen += ptrServerList->FillPacketBufferWithIPs(&position, packetbuffer+6, MAX_PACKET_LENGTH-6, 0, NULL);
|
|
||||||
|
|
||||||
OUT_SendSpecificReply(packetbuffer, packetlen, DestinationAddress);
|
|
||||||
ptrIO->inc_d_ServerListPacketsSent();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: OUT_j_SendAck
|
|
||||||
//
|
|
||||||
// Not any creativity here. We just fire a quick, constant message out.
|
|
||||||
*/
|
|
||||||
void PacketManagement::OUT_j_SendAck(struct sockaddr_in DestinationAddress) {
|
|
||||||
|
|
||||||
OUT_SendSpecificReply("\xff\xff\xff\xff" "j", strlen("\xff\xff\xff\xff" "j"), DestinationAddress);
|
|
||||||
ptrIO->inc_j_ACKPacketsSent();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: OUT_y_SendModRequest
|
|
||||||
//
|
|
||||||
// Much like when we return servers, we attempt to return as many mods as we
|
|
||||||
// can in one packet, and give HL something to let it continue later. It's
|
|
||||||
// not a hash that HL returns this time--it's a string.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
void PacketManagement::OUT_y_SendModRequest(struct sockaddr_in DestinationAddress, const char * Mod) {
|
|
||||||
|
|
||||||
unsigned int packetlen = 6;
|
|
||||||
|
|
||||||
//The char we were given a pointer to is packetbuffer, we need a copy.
|
|
||||||
//Fixme: a bit roundabout, pass a hash or something instead.
|
|
||||||
char TempArray[64];
|
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
//This is pretty much a strncpy that doesn't copy non-printable chars.
|
|
||||||
while(*Mod != '\0' && offset < 63) { //gibberish bypassing
|
|
||||||
|
|
||||||
if(isprint(*Mod) != 0) {
|
|
||||||
|
|
||||||
TempArray[offset] = *Mod;
|
|
||||||
offset++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mod++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(offset < 1) { return; } //Wouldn't crash us, but wastes our time.
|
|
||||||
TempArray[offset] = '\0';
|
|
||||||
|
|
||||||
strcpy(packetbuffer, "\xff\xff\xff\xff" "y\n");
|
|
||||||
|
|
||||||
packetlen += ptrMods->FillPacketBufferWithMods(TempArray, packetbuffer+6, MAX_PACKET_LENGTH-6);
|
|
||||||
|
|
||||||
OUT_SendSpecificReply(packetbuffer, packetlen, DestinationAddress);
|
|
||||||
ptrIO->inc_y_ModReplyPacketsSent();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: OUT_SendClientPing
|
|
||||||
//
|
|
||||||
// Sends the HL ping packet to a server. Useful when verifying shutdowns.
|
|
||||||
*/
|
|
||||||
void PacketManagement::OUT_SendClientPing(struct sockaddr_in DestinationAddress) {
|
|
||||||
|
|
||||||
OUT_SendSpecificReply("\xff\xff\xff\xff" "ping", strlen("\xff\xff\xff\xff" "ping"), DestinationAddress);
|
|
||||||
ptrIO->inc___PingPacketsSent();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: OUT_SendSpecificReply
|
|
||||||
//
|
|
||||||
// Mostly just a sendto wrapper, this is public to allow other things to send--
|
|
||||||
// such as WONnetwk, which handles w packets.
|
|
||||||
*/
|
|
||||||
void PacketManagement::OUT_SendSpecificReply(char* SendingPacket, unsigned int SizeofPacket, struct sockaddr_in DestinationAddress) {
|
|
||||||
if(sendto(socket_GLOBAL, SendingPacket, SizeofPacket, 0, (struct sockaddr *)&DestinationAddress, sizeof(DestinationAddress)) == SOCKET_ERROR) {
|
|
||||||
PRINTERROR;
|
|
||||||
}
|
|
||||||
ptrIO->UpdateBytesSent(SizeofPacket);
|
|
||||||
ptrIO->inc___TotalPacketsSent();
|
|
||||||
ptrIO->OutputFileData(4, "PACKET sent, size:%i\n", CurrentNumberOfBytesReceived);
|
|
||||||
ptrIO->OutputFileDataRaw(4, packetbuffer, CurrentNumberOfBytesReceived);
|
|
||||||
ptrIO->OutputFileData(4, "\n");
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
/* 'Port' is intended to handle EVERYTHING that is needed between
|
|
||||||
// windows and unix. Includes, decs, defines, and some code
|
|
||||||
// will go here. If things get too hairy, I'll go back to the
|
|
||||||
// traditional IF/ELSE blocks in the code, but right now this
|
|
||||||
// is pretty good.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __MASTER__SERVER__PORTABILITY_H_
|
|
||||||
#define __MASTER__SERVER__PORTABILITY_H_
|
|
||||||
|
|
||||||
//No reliance on compiler. Define the right one, don't be stupid and do
|
|
||||||
//something like define them all.
|
|
||||||
#define __MASTER_SERVER_USING_WIN32
|
|
||||||
//#define __MASTER_SERVER_USING_UNIX
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __MASTER_SERVER_USING_WIN32
|
|
||||||
|
|
||||||
#include <winsock.h>
|
|
||||||
#define LIBCONFIG "libconfig101windows\libconfig.h"
|
|
||||||
#define __OS__ "Windows"
|
|
||||||
#define close closesocket
|
|
||||||
#define usleep sleep
|
|
||||||
#define sleep(x) Sleep(x*1000)
|
|
||||||
|
|
||||||
#define DoWindowsNetThing(); \
|
|
||||||
WSADATA wsa; \
|
|
||||||
if ((WSAStartup(MAKEWORD(1, 1), &wsa)) != 0) { return 255; }
|
|
||||||
|
|
||||||
#define PRINTERROR Printf(1, "Socket Error %i line %u file %s\n", WSAGetLastError(), __LINE__, __FILE__)
|
|
||||||
typedef int socklen_t;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __MASTER_SERVER_USING_UNIX
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
|
|
||||||
#define LIBCONFIG "libconfig101unix/libconfig.h"
|
|
||||||
#define LIBOPTIONS "options/options.h"
|
|
||||||
#define __OS__ "Linux"
|
|
||||||
|
|
||||||
#define WSAGetLastError() errno
|
|
||||||
#define WSAENETRESET ENETRESET
|
|
||||||
#define PRINTERROR ptrIO->OutputWindowPrintf(1, "Socket Error %i\n", errno)
|
|
||||||
#define WSACleanup();
|
|
||||||
#define DoWindowsNetThing();
|
|
||||||
#define INVALID_SOCKET -1
|
|
||||||
#define SOCKET_ERROR -1 //Defined to different signs... Damn Microsoft.
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,156 +0,0 @@
|
|||||||
#ifndef HLDS_LINUX_FS_REMAKE
|
|
||||||
#define HLDS_LINUX_FS_REMAKE
|
|
||||||
|
|
||||||
#include "Q_memdef.h"
|
|
||||||
#include "endianin.h"
|
|
||||||
#include <stdarg.h>
|
|
||||||
//This particular chunk of the code--file IO--requires C++ libs. Therefore
|
|
||||||
//the external functions that we hijack must be left un-mangled with extern "C".
|
|
||||||
|
|
||||||
//These defines are arbitrary, but if you end up dereferencing a file pointer
|
|
||||||
//in a debugger, they read 'file' 'none', and 'pak '
|
|
||||||
#define HL_FILE_UNASSIGNED 0x656e6F6e
|
|
||||||
#define HL_FILE_REGULAR 0x656c6966
|
|
||||||
//#define HL_FILE_WRITEONLY 0x
|
|
||||||
//#define HL_FILE_READWRITE 0xEDFA0500
|
|
||||||
#define HL_FILE_ARCHIVEREADONLY 0x206b6170
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
typedef class hl_pak_file_s {
|
|
||||||
|
|
||||||
private:
|
|
||||||
int identifier;
|
|
||||||
|
|
||||||
public:
|
|
||||||
hl_pak_file_s();
|
|
||||||
~hl_pak_file_s();
|
|
||||||
} hl_pak_file_t;
|
|
||||||
|
|
||||||
typedef class hl_file_s {
|
|
||||||
|
|
||||||
int identifier;
|
|
||||||
|
|
||||||
//a little waste, but oh well, deal with it later.
|
|
||||||
boost::filesystem::filebuf file;
|
|
||||||
// class hl_pak_file_s embeddedPAK;
|
|
||||||
|
|
||||||
public:
|
|
||||||
hl_file_s();
|
|
||||||
~hl_file_s();
|
|
||||||
void OpenFile(const boost::filesystem::path &, std::ios_base::openmode);
|
|
||||||
int OpenFileNoThrow(const boost::filesystem::path &, std::ios_base::openmode);
|
|
||||||
void Close();
|
|
||||||
int GetFileSize();
|
|
||||||
int ReadFile(char *, std::streamsize);
|
|
||||||
int WriteFile(char *, std::streamsize);
|
|
||||||
int Seekg(long int, std::ios_base::seekdir);
|
|
||||||
int Seekp(long int, std::ios_base::seekdir);
|
|
||||||
int Tellg();
|
|
||||||
int Tellp();
|
|
||||||
int Sync();
|
|
||||||
int IsEoF();
|
|
||||||
int Error();
|
|
||||||
} hl_file_t;
|
|
||||||
#else
|
|
||||||
|
|
||||||
//These exist so that C functions don't have to resort to passing void *s to objects.
|
|
||||||
//Them adding, subtracting, or generally messing with the data in any way is a bad idea.
|
|
||||||
|
|
||||||
//For some reason one of my GCCs chokes on this. And by 'this' I mean any typedef struct
|
|
||||||
//at this particular location. Why this location, I do not know. Preprocessor bug?
|
|
||||||
//Must be; it works on newer versions.
|
|
||||||
typedef struct hl_pak_file_s hl_pak_file_t;
|
|
||||||
|
|
||||||
typedef struct hl_file_s hl_file_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//The mostly unused FSMC functions
|
|
||||||
|
|
||||||
void FSMC_HintFileShouldStayInCache(void * arg0);
|
|
||||||
void FSMC_HintResourcesNeeded(void * arg0);
|
|
||||||
void FSMC_SetPreloadEnabled(int arg0); //bool methinks
|
|
||||||
|
|
||||||
//The HL FS functions
|
|
||||||
void FS_AddSearchPath(const char *arg0, char *arg4, int arg8);
|
|
||||||
void FS_Close(hl_file_t *arg0);
|
|
||||||
void FS_CreateDirHierarchy(char *arg0, char *arg4);
|
|
||||||
int FS_EndOfFile(hl_file_t *arg0);
|
|
||||||
int FS_FPrintf(hl_file_t *arg0, const char *arg4, ...);
|
|
||||||
int FS_FileExists(char *arg0);
|
|
||||||
int FS_FileSize(char *arg0); //not in 386
|
|
||||||
void Sys_FindClose();
|
|
||||||
const char * Sys_FindFirst(const char *arg0, char *arg4); //or is it two char*?
|
|
||||||
const char * Sys_FindNext(char *arg0);
|
|
||||||
int FS_Flush(hl_file_t *arg0);
|
|
||||||
int FS_GetFileTime(char *arg0);
|
|
||||||
int FS_GetGameDir(char *, int);
|
|
||||||
void FS_GetInterfaceVersion(char *arg0, int arg4);
|
|
||||||
void FS_GetLocalCopy(char *arg0);
|
|
||||||
char * FS_GetLocalPath(char *arg0, char *arg4, int arg8);
|
|
||||||
void * FS_GetReadBuffer(void *arg0, int *arg4);
|
|
||||||
int FS_HintResourceNeed(char *arg0, int arg4);
|
|
||||||
int FS_IsOk(hl_file_t *arg0);
|
|
||||||
int FS_LoadLibrary(char *arg0);
|
|
||||||
void FS_LogLevelLoadStarted(char *arg0);
|
|
||||||
hl_file_t * FS_Open(const char *arg0, const char *arg4);
|
|
||||||
hl_file_t * FS_OpenPathID(const char *arg0, const char *arg4, const char *arg8);
|
|
||||||
int FS_Read(void *arg0, size_t arg4, size_t arg8, hl_file_t *argC);
|
|
||||||
void FS_ReleaseReadBuffer(void *arg0, void *arg4);
|
|
||||||
void FS_RemoveFile(char *arg0);
|
|
||||||
int FS_Rename(char *arg0, char *arg4);
|
|
||||||
int FS_Seek(hl_file_t *arg0, long int arg4, int arg8);
|
|
||||||
int FS_Size(hl_file_t *arg0);
|
|
||||||
int FS_Tell(hl_file_t *arg0);
|
|
||||||
int FS_Unlink(char * arg0);
|
|
||||||
int FS_Write(void *arg0, size_t arg4, size_t arg8, hl_file_t *argC);
|
|
||||||
int FileCopy(hl_file_t *arg0, hl_file_t *arg4, int arg8);
|
|
||||||
int FileSize(void *arg0);
|
|
||||||
int FileSystem_Init(char * arg0);
|
|
||||||
int FileSystem_SetGameDirectory(const char * arg0, const char * arg4);
|
|
||||||
void FileSystem_Shutdown();
|
|
||||||
int FileSystem_LoadDLL__FPFPCcPi_P14IBaseInterface(void * function0);
|
|
||||||
void FileSystem_UnloadDLL__Fv();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//The functions that are empty or unused in the Linux stdio binary
|
|
||||||
void FSMC_FlushAccessedFiles(void);
|
|
||||||
void FSMC_FlushAllFiles(void);
|
|
||||||
void FSMC_HintFileNeeded(void * arg0);
|
|
||||||
int FSMC_IsFileInCache(void * arg0, void * arg4); //unused
|
|
||||||
void FSMC_PausePreloadThread(void);
|
|
||||||
void FSMC_ReportUsage(void);
|
|
||||||
void FSMC_ResumePreloadThread(void);
|
|
||||||
void FS_CancelWaitForResources(hl_file_t *arg0);
|
|
||||||
void FS_FileTimeToString(char *arg0, int arg4, long int arg8);
|
|
||||||
int FS_FindIsDirectory(void * arg0);
|
|
||||||
int FS_FullPathToRelativePath(char * arg0, char * arg4);
|
|
||||||
int FS_GetCharacter(hl_file_t *arg0);
|
|
||||||
int FS_GetCurrentDirectory(char *arg0, int arg4);
|
|
||||||
int FS_GetWaitForResourcesProgress(int arg0, float * arg4, int arg8);
|
|
||||||
int FS_IsDirectory(char * arg0);
|
|
||||||
void FS_LogLevelLoadFinished(char *arg0);
|
|
||||||
int FS_ParseFile(char *arg0, char *arg4, int arg8);
|
|
||||||
int FS_PauseResourcePreloading();
|
|
||||||
void FS_PrintOpenedFiles();
|
|
||||||
char * FS_ReadLine(char *arg0, int arg4, hl_file_t *arg8);
|
|
||||||
int FS_RemoveSearchPath(char *arg0, char *arg4);
|
|
||||||
void FS_RemoveAllSearchPaths();
|
|
||||||
int FS_ResumeResourcePreloading();
|
|
||||||
int FS_SetVBuf(void *arg0, char *arg4, int arg8, long argC);
|
|
||||||
void FS_SetWarningFunc(void * arg0);
|
|
||||||
void FS_SetWarningLevel(void * arg0);
|
|
||||||
int FS_WaitForResources(char * arg0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "HIJACK.h"
|
|
||||||
#include "cvar.h"
|
|
||||||
#include "pf.h"
|
|
||||||
#include "report.h"
|
|
||||||
#include "Mod.h"
|
|
||||||
#include "VecMath.h"
|
|
||||||
#include "R.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//non-hijacked \stuff
|
|
||||||
//Current status: all header files functional. All C files work except SV_hlds.c
|
|
||||||
//SV_CreatePacketEntities is responsible for trouble.
|
|
||||||
|
|
||||||
//static void *enginesolib = NULL;
|
|
||||||
|
|
||||||
BlendingAPI_t * g_pSvBlendingAPI = NULL;
|
|
||||||
Mod_DLL_Functions_t gEntityInterface;
|
|
||||||
SecurityModule_t g_modfuncs;
|
|
||||||
g_vars_t gGlobalVariables;
|
|
||||||
|
|
||||||
client_t * host_client = NULL;
|
|
||||||
double host_frametime;
|
|
||||||
int giActive;
|
|
||||||
|
|
||||||
|
|
||||||
client_static_t cls;
|
|
||||||
server_static_t svs;
|
|
||||||
server_t sv;
|
|
||||||
|
|
||||||
double realtime;
|
|
||||||
|
|
||||||
|
|
||||||
int sv_playermodel;
|
|
||||||
vec3_t player_mins[5] = { { -16, -16, -36 },
|
|
||||||
{ -16, -16, -18 },
|
|
||||||
{ 0, 0, 0 },
|
|
||||||
{ -32, -32, -32 },
|
|
||||||
{ 0, 0, 0 } };
|
|
||||||
vec3_t player_maxs[5] = { { 16, 16, 36 },
|
|
||||||
{ 16, 16, 18 },
|
|
||||||
{ 0, 0, 0 },
|
|
||||||
{ 32, 32, 32 },
|
|
||||||
{ 0, 0, 0 } };
|
|
||||||
|
|
||||||
char com_clientfallback[0x104];
|
|
||||||
int allow_cheats;
|
|
||||||
netadr_t sUpdateIPAddress;
|
|
||||||
movevars_t movevars;
|
|
||||||
|
|
||||||
netadr_t net_from;
|
|
||||||
sizebuf_t net_message;
|
|
||||||
netadr_t net_local_adr;
|
|
||||||
int net_drop;
|
|
||||||
qboolean noip;
|
|
||||||
|
|
||||||
playermove_t * pmove = NULL;
|
|
||||||
playermove_t g_svmove;
|
|
||||||
edict_t * sv_player = NULL;
|
|
||||||
int key_dest;
|
|
||||||
sv_delta_t * g_sv_delta = NULL;
|
|
||||||
int g_groupop;
|
|
||||||
int g_groupmask;
|
|
||||||
NEW_DLL_FUNCTIONS_t gNewDLLFunctions;
|
|
||||||
char * pr_strings = NULL;
|
|
||||||
int gfUseLANAuthentication;
|
|
||||||
|
|
||||||
char localinfo[0x8001];
|
|
||||||
|
|
||||||
char * wadpath = NULL;
|
|
||||||
char texgammatable[0x100];
|
|
||||||
texture_t * r_notexture_mip = NULL;
|
|
||||||
int r_pixbytes = 1;
|
|
||||||
|
|
||||||
int sv_decalnamecount = 0;
|
|
||||||
char (sv_decalnames)[0x200][0x11];
|
|
||||||
|
|
||||||
char (localmodels)[512][5];
|
|
||||||
int host_hunklevel;
|
|
||||||
|
|
||||||
|
|
||||||
edict_t ** g_moved_edict = NULL;
|
|
||||||
vec3_t * g_moved_from = NULL;
|
|
||||||
|
|
||||||
float (bonetransform)[0x80][3][4];
|
|
||||||
float (rotationmatrix)[3][4];
|
|
||||||
|
|
||||||
int g_iextdllMac;
|
|
||||||
DLLlist_t (g_rgextdll)[50];
|
|
||||||
|
|
||||||
|
|
||||||
gpnewusermsg_struct_t * sv_gpNewUserMsg = NULL;
|
|
||||||
gpnewusermsg_struct_t * sv_gpUserMsg = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//SV_ValidClientMulticast: Bad argument 132
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
/* All that hijacking is here now
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef HLDS_LINUX_ENGINE_HIJACK
|
|
||||||
#define HLDS_LINUX_ENGINE_HIJACK
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "Q_memdef.h"
|
|
||||||
#include "report.h"
|
|
||||||
#include "common.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "delta.h"
|
|
||||||
#include "SV_hlds.h"
|
|
||||||
#include "cmd.h"
|
|
||||||
#include "edict.h"
|
|
||||||
|
|
||||||
/* Engine function type stuff. The mod needs the addresses of the engine, well,
|
|
||||||
// the engine needs mod addresses as well. Note eiface.h and cbase.h/cpp.
|
|
||||||
*/
|
|
||||||
typedef void SAVERESTOREDATA; //It's a large struct but I don't feel like digging it out
|
|
||||||
|
|
||||||
typedef void KeyValueData;
|
|
||||||
typedef void TYPEDESCRIPTION;
|
|
||||||
|
|
||||||
typedef struct DLLlist_s {
|
|
||||||
|
|
||||||
void * dll;
|
|
||||||
#ifdef USING_UNIX_BABY
|
|
||||||
void * SymbolTable; //unused on unix
|
|
||||||
#else
|
|
||||||
void * SymbolTable;
|
|
||||||
#endif
|
|
||||||
int NumSymbols;
|
|
||||||
} DLLlist_t;
|
|
||||||
|
|
||||||
typedef struct Mod_DLL_Functions_s { //50 functions, 200 bytes
|
|
||||||
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnGameInit) (void);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnSpawn) (edict_t *pent);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnThink) (edict_t *pent);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnUse) (edict_t *pentUsed, edict_t *pentOther);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnTouch) (edict_t *pentTouched, edict_t *pentOther);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnBlocked) (edict_t *pentBlocked, edict_t *pentOther);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnKeyValue) (edict_t *pentKeyvalue, KeyValueData *pkvd);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSave) (edict_t *pent, SAVERESTOREDATA *pSaveData);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnRestore) (edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSetAbsBox) (edict_t *pent);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSaveWriteFields) (SAVERESTOREDATA *, const char *, void *, TYPEDESCRIPTION *, int);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSaveReadFields) (SAVERESTOREDATA *, const char *, void *, TYPEDESCRIPTION *, int);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSaveGlobalState) (SAVERESTOREDATA *);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnRestoreGlobalState) (SAVERESTOREDATA *);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnResetGlobalState) (void);
|
|
||||||
qboolean MOD_STD_CALLING_IMPORTED (*pfnClientConnect) (edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnClientDisconnect) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnClientKill) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnClientPutInServer) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnClientCommand) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnClientUserInfoChanged) (edict_t *pEntity, char *infobuffer);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnServerActivate) (edict_t *pEdictList, int edictCount, int clientMax);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnServerDeactivate) (void);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnPlayerPreThink) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnPlayerPostThink) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnStartFrame) (void);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnParmsNewLevel) (void);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnParmsChangeLevel) (void);
|
|
||||||
const char * MOD_STD_CALLING_IMPORTED (*pfnGetGameDescription) (void);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnPlayerCustomization) (edict_t *pEntity, customization_t *pCustom);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSpectatorConnect) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSpectatorDisconnect) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSpectatorThink) (edict_t *pEntity);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSys_Error) (const char *error_string);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnPM_Move) (playermove_t *ppmove, qboolean server);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnPM_Init) (playermove_t *ppmove);
|
|
||||||
char MOD_STD_CALLING_IMPORTED (*pfnPM_FindTextureType) (char *name);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnSetupVisibility) (edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnUpdateClientData) (const edict_t *ent, int sendweapons, clientdata_t *cd);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnAddToFullPack) (entity_state_t *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnCreateBaseline) (int player, int eindex, entity_state_t *baseline, edict_t *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnRegisterEncoders) (void );
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnGetWeaponData) (edict_t *player, weapon_data_t *info);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnCmdStart) (const edict_t *player, const usercmd_t *cmd, unsigned int random_seed);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnCmdEnd) (const edict_t *player);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnConnectionlessPacket) (const netadr_t *net_from, const char *args, char *response_buffer, int *response_buffer_size);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnGetHullBounds) (int hullnumber, float *mins, float *maxs);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnCreateInstancedBaselines) (void);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnInconsistentFile) (const edict_t *player, const char *filename, char *disconnect_message);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnAllowLagCompensation) (void);
|
|
||||||
} Mod_DLL_Functions_t;
|
|
||||||
|
|
||||||
typedef struct SecurityModule_s { //unknown; not even known to be a security module.
|
|
||||||
|
|
||||||
void (*Function1) (void);
|
|
||||||
void (*Function2) (void);
|
|
||||||
void (*Function3) (void);
|
|
||||||
void (*Function4) (void);
|
|
||||||
void (*Function5) (void);
|
|
||||||
void (*Function6) (void);
|
|
||||||
void (*Function7) (netchan_t *, sizebuf_t *);
|
|
||||||
int (*Function8) (netchan_t *, sizebuf_t *); //1c
|
|
||||||
void (*Function9) (void);
|
|
||||||
void (*Function10) (model_t *, byte *);
|
|
||||||
void (*Function11) (void);
|
|
||||||
void (*Function12) (void);
|
|
||||||
void (*Function13) (void);
|
|
||||||
void (*Function14) (void);
|
|
||||||
void (*Function15) (void);
|
|
||||||
void (*Function16) (void);
|
|
||||||
void (*Function17) (void);
|
|
||||||
void (*Function18) (int); //44
|
|
||||||
void (*Function19) (void);
|
|
||||||
void (*Function20) (byte *, int); //4c
|
|
||||||
void (*Function21) (void);
|
|
||||||
void (*Function22) (void);
|
|
||||||
void (*Function23) (void);
|
|
||||||
void (*Function24) (void);
|
|
||||||
void (*Function25) (void);
|
|
||||||
void (*Function26) (void);
|
|
||||||
void (*Function27) (void);
|
|
||||||
void (*Function28) (void);
|
|
||||||
void (*Function29) (void);
|
|
||||||
} SecurityModule_t;
|
|
||||||
|
|
||||||
typedef struct NEW_DLL_FUNCTIONS_s{ //Three functions.
|
|
||||||
// Called right before the object's memory is freed.
|
|
||||||
// Calls its destructor.
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnOnFreeEntPrivateData)(edict_t *pEnt);
|
|
||||||
void MOD_STD_CALLING_IMPORTED (*pfnGameShutdown)(void);
|
|
||||||
int MOD_STD_CALLING_IMPORTED (*pfnShouldCollide)( edict_t *pentTouched, edict_t *pentOther );
|
|
||||||
} NEW_DLL_FUNCTIONS_t;
|
|
||||||
|
|
||||||
typedef struct BlendingAPI_s {
|
|
||||||
|
|
||||||
int padding00;
|
|
||||||
void (*BoneSetup)(model_t *, float, int, vec3_t, vec3_t, byte *, byte *, int, edict_t *); //SV_StudioSetupBones
|
|
||||||
|
|
||||||
} BlendingAPI_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//History: Until this was standalone, a lot of variables were placed here
|
|
||||||
//and dynamically linked to. ALmost all of these followed the same format--
|
|
||||||
//a pointer to the object, with the HIJACK define dereferencing the pointer.
|
|
||||||
//I did it that way so that I could simly remove the dereferencing and have them
|
|
||||||
//be global variables when it was time to unhijack everything and make a
|
|
||||||
//standalone release. It worked. These vars DO need to be moved
|
|
||||||
//to appropriate files, but for now, it works.
|
|
||||||
|
|
||||||
/*** EXTERN ***/
|
|
||||||
extern BlendingAPI_t * g_pSvBlendingAPI;
|
|
||||||
|
|
||||||
extern Mod_DLL_Functions_t gEntityInterface;
|
|
||||||
extern SecurityModule_t g_modfuncs;
|
|
||||||
extern g_vars_t gGlobalVariables;
|
|
||||||
|
|
||||||
|
|
||||||
extern client_t * host_client; //can NOT be released
|
|
||||||
extern double host_frametime;
|
|
||||||
extern int giActive;
|
|
||||||
|
|
||||||
extern netadr_t net_local_adr;
|
|
||||||
extern netadr_t net_from;
|
|
||||||
extern sizebuf_t net_message;
|
|
||||||
extern int net_drop;
|
|
||||||
extern qboolean noip;
|
|
||||||
|
|
||||||
extern client_static_t cls;
|
|
||||||
|
|
||||||
extern server_static_t svs;
|
|
||||||
extern server_t sv;
|
|
||||||
|
|
||||||
extern edict_t * sv_player;
|
|
||||||
extern int key_dest;
|
|
||||||
extern sv_delta_t * g_sv_delta;
|
|
||||||
|
|
||||||
extern int g_groupop;
|
|
||||||
extern int g_groupmask;
|
|
||||||
extern NEW_DLL_FUNCTIONS_t gNewDLLFunctions;
|
|
||||||
extern char * pr_strings;
|
|
||||||
|
|
||||||
extern char localinfo[0x8001];
|
|
||||||
|
|
||||||
|
|
||||||
extern double realtime;
|
|
||||||
|
|
||||||
extern edict_t ** g_moved_edict;
|
|
||||||
extern vec3_t * g_moved_from;
|
|
||||||
|
|
||||||
extern char * wadpath; // Path of wad files associated with current BSP
|
|
||||||
extern char texgammatable[0x100];
|
|
||||||
extern texture_t * r_notexture_mip;
|
|
||||||
extern int r_pixbytes;
|
|
||||||
|
|
||||||
extern int sv_playermodel;
|
|
||||||
extern vec3_t player_mins[5]; //These two may be constants. vec3_t[4]
|
|
||||||
extern vec3_t player_maxs[5];
|
|
||||||
|
|
||||||
extern char com_clientfallback[0x104];
|
|
||||||
extern int allow_cheats;
|
|
||||||
extern netadr_t sUpdateIPAddress;
|
|
||||||
extern movevars_t movevars;
|
|
||||||
|
|
||||||
extern playermove_t * pmove;
|
|
||||||
extern playermove_t g_svmove;
|
|
||||||
|
|
||||||
extern int gfUseLANAuthentication;
|
|
||||||
extern gpnewusermsg_struct_t * sv_gpNewUserMsg;
|
|
||||||
extern gpnewusermsg_struct_t * sv_gpUserMsg;
|
|
||||||
|
|
||||||
extern int sv_decalnamecount;
|
|
||||||
extern char (sv_decalnames)[0x200][0x11];
|
|
||||||
|
|
||||||
extern vec_t (bonetransform)[0x80][3][4];
|
|
||||||
extern vec_t (rotationmatrix)[3][4];
|
|
||||||
|
|
||||||
extern char (localmodels)[512][5];
|
|
||||||
extern int host_hunklevel;
|
|
||||||
|
|
||||||
extern int g_iextdllMac;
|
|
||||||
extern DLLlist_t (g_rgextdll)[50];
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,868 +0,0 @@
|
|||||||
#include "HUNK.h"
|
|
||||||
|
|
||||||
#include "report.h"
|
|
||||||
#include "common.h"
|
|
||||||
#include "cmd.h"
|
|
||||||
|
|
||||||
/*** DEFINES ***/
|
|
||||||
|
|
||||||
#define HUNK_ARRAYNAMELENGTH 64
|
|
||||||
#define HUNK_SENTINAL 0x1df001ed
|
|
||||||
#define ZONEID 0x1d4a11
|
|
||||||
#define ZONESENTINAL 0xdeadbeaf
|
|
||||||
#define MINFRAGMENT 64
|
|
||||||
|
|
||||||
|
|
||||||
/*** SRUCTS ***/
|
|
||||||
|
|
||||||
typedef struct hunk_s {
|
|
||||||
uint32 sentinal;
|
|
||||||
unsigned int size;
|
|
||||||
char name[HUNK_ARRAYNAMELENGTH]; //it's definitely not 8
|
|
||||||
} hunk_t;
|
|
||||||
typedef struct cache_system_s {
|
|
||||||
unsigned int size; //4
|
|
||||||
cache_user_t *user; //8
|
|
||||||
char name[64]; //72-8=64
|
|
||||||
struct cache_system_s *prev, *next, *lru_prev, *lru_next;
|
|
||||||
int locked;
|
|
||||||
//The actual allocated data follows this struct.
|
|
||||||
} cache_system_t;
|
|
||||||
typedef struct memblock_s {
|
|
||||||
unsigned int size; // including the header and possibly tiny fragments
|
|
||||||
int tag; // a tag of 0 is a free block
|
|
||||||
uint32 id; // should be ZONEID
|
|
||||||
struct memblock_s *next, *prev;
|
|
||||||
int pad; // pad to 64 bit boundary
|
|
||||||
} memblock_t;
|
|
||||||
typedef struct memzone_s {
|
|
||||||
unsigned int size; // total bytes malloced, including header
|
|
||||||
memblock_t blocklist; // start / end cap for linked list
|
|
||||||
memblock_t *rover;
|
|
||||||
} memzone_t;
|
|
||||||
|
|
||||||
|
|
||||||
/*** GLOBALS ***/
|
|
||||||
|
|
||||||
static byte * sg_hunk_base = NULL;
|
|
||||||
static uint32 sg_hunk_size = 0;
|
|
||||||
static uint32 sg_hunk_low_used = 0;
|
|
||||||
static uint32 sg_hunk_high_used = 0;
|
|
||||||
static BOOL sg_hunk_tempactive = 0;
|
|
||||||
static int sg_hunk_tempmark = 0;
|
|
||||||
|
|
||||||
static memzone_t * sg_mainzone = NULL;
|
|
||||||
static cache_system_t sg_cache_head = { 0, NULL, "", NULL, NULL, NULL, NULL, 0 };
|
|
||||||
|
|
||||||
|
|
||||||
/*** FUNCTIONS ***/
|
|
||||||
|
|
||||||
//hunk
|
|
||||||
void *Hunk_Alloc(unsigned int);
|
|
||||||
|
|
||||||
void *Hunk_HighAllocName(unsigned int, char*);
|
|
||||||
void Hunk_Check(void);
|
|
||||||
void Hunk_Print(/*qboolean*/);
|
|
||||||
|
|
||||||
|
|
||||||
//cache
|
|
||||||
void Cache_Init();
|
|
||||||
cache_system_t * Cache_TryAlloc(unsigned int, qboolean);
|
|
||||||
void Cache_MakeLRU(cache_system_t *);
|
|
||||||
void Cache_UnlinkLRU(cache_system_t *);
|
|
||||||
|
|
||||||
void Cache_Move(cache_system_t *);
|
|
||||||
void Cache_Flush();
|
|
||||||
|
|
||||||
void Cache_FreeLow(unsigned int);
|
|
||||||
void Cache_FreeHigh(unsigned int);
|
|
||||||
|
|
||||||
|
|
||||||
//Z
|
|
||||||
void Z_ClearZone(memzone_t *, unsigned int);
|
|
||||||
void *Z_TagMalloc(unsigned int, int);
|
|
||||||
void Z_Print(/*memzone_t **/);
|
|
||||||
void Z_CheckHeap(void);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: Memory_Init
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Load__7CEnginebPcT2->Sys_InitGame__FPcT0Pvi->Host_Init->Memory_Init
|
|
||||||
//
|
|
||||||
// Inits the big chunk of memory used for now and ever. Appears to follow
|
|
||||||
// QW's example, with NOZONE undefined
|
|
||||||
*/
|
|
||||||
void Memory_Init(void *buf, unsigned int bufsize) {
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int zonesize = 0x200000; //this appears to be a default cache size
|
|
||||||
const char * retp;
|
|
||||||
|
|
||||||
sg_hunk_base = (byte *)buf;
|
|
||||||
sg_hunk_size = bufsize;
|
|
||||||
sg_hunk_low_used = 0;
|
|
||||||
sg_hunk_high_used = 0;
|
|
||||||
|
|
||||||
Cache_Init();
|
|
||||||
|
|
||||||
//COM_CheckParm is a function that returns the position (as in argv[])
|
|
||||||
//that a given parameter is at (or 0 if it doesn't exist).
|
|
||||||
|
|
||||||
//We can then check the global argument list at that location and see what's
|
|
||||||
//inside.
|
|
||||||
|
|
||||||
retp = COM_GetParmAfterParm("-zone");
|
|
||||||
if(retp[0] != '\0') {
|
|
||||||
zonesize = (Q_atoi(retp) << 10); // This flags up a 'const discard' warning on my Fedora install, but not on Windows.
|
|
||||||
}
|
|
||||||
sg_mainzone = Hunk_AllocName(zonesize, "zone");
|
|
||||||
|
|
||||||
if (sg_mainzone == NULL) {
|
|
||||||
Sys_Error("Memory_Init: Zone allocation failed. Check -zone and/or -heapsize switches\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
Z_ClearZone(sg_mainzone, zonesize);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** HUNK ***/
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_Alloc
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: All over
|
|
||||||
//
|
|
||||||
// Calls hunk_allocName with a generic name
|
|
||||||
*/
|
|
||||||
void *Hunk_Alloc(unsigned int size) {
|
|
||||||
|
|
||||||
return(Hunk_AllocName(size, "noname"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_AllocName
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: All over
|
|
||||||
//
|
|
||||||
// Carves a chunk of the hunk
|
|
||||||
*/
|
|
||||||
void *Hunk_AllocName(unsigned int size, const char *name) {
|
|
||||||
|
|
||||||
hunk_t *h;
|
|
||||||
unsigned int freespace = sg_hunk_size - sg_hunk_low_used - sg_hunk_high_used;
|
|
||||||
unsigned int totalsize = sizeof(hunk_t) + ((size+15)&~15);
|
|
||||||
|
|
||||||
if(totalsize < size || totalsize > freespace) { //overflow catching
|
|
||||||
Sys_Error ("Hunk_AllocName: Requested size %u, padded to size %u, total free hunk is %u", size, totalsize, freespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
h = (hunk_t *)(sg_hunk_base + sg_hunk_low_used);
|
|
||||||
|
|
||||||
sg_hunk_low_used += totalsize;
|
|
||||||
Cache_FreeLow(sg_hunk_low_used);
|
|
||||||
|
|
||||||
memset(h, 0, totalsize);
|
|
||||||
|
|
||||||
|
|
||||||
h->size = totalsize;
|
|
||||||
h->sentinal = HUNK_SENTINAL;
|
|
||||||
|
|
||||||
/* Orginally this in the QW source was Q_strncpyz with a call to COM_SkipPath in there.
|
|
||||||
// Skippath() basically ignored anything before a forward slash.
|
|
||||||
// The strcpy rewrite looked to just be strncpy with a precautionary null tacked on.
|
|
||||||
// well I didn't do all that. We zero'd out the structure; if we copy 63 bytes
|
|
||||||
// we should be guaranteed a properly terminated string.
|
|
||||||
//
|
|
||||||
// The paths could cause trouble. What if it's ungodly long and all unique
|
|
||||||
// names are truncated? Well HL didn't worry about it, neither will I.
|
|
||||||
// Besides I'm not a modder. That's their problem.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Q_strncpy(h->name, name, HUNK_ARRAYNAMELENGTH-1);
|
|
||||||
|
|
||||||
return(void *)(h+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_TempAlloc
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Mods I think
|
|
||||||
//
|
|
||||||
// Allocates with the name 'temp'. A small block of code seems to exist to
|
|
||||||
// purge thigns allocated as 'temp' from time to time. It looks like only
|
|
||||||
// one temp is allowed at a given time.
|
|
||||||
*/
|
|
||||||
void *Hunk_TempAlloc(unsigned int size) {
|
|
||||||
|
|
||||||
void *buf;
|
|
||||||
|
|
||||||
// size = (size+15)&~15; //unnecessary; hunkhighallocname does this already
|
|
||||||
|
|
||||||
if(sg_hunk_tempactive) {
|
|
||||||
sg_hunk_tempactive = 0;
|
|
||||||
Hunk_FreeToHighMark(sg_hunk_tempmark);
|
|
||||||
}
|
|
||||||
|
|
||||||
sg_hunk_tempmark = Hunk_HighMark();
|
|
||||||
|
|
||||||
buf = Hunk_HighAllocName(size, "temp");
|
|
||||||
|
|
||||||
sg_hunk_tempactive = 1;
|
|
||||||
|
|
||||||
return(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_HighAllocName
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH:
|
|
||||||
//
|
|
||||||
// Carves an upper chunk of the hunk; can fail.
|
|
||||||
*/
|
|
||||||
void *Hunk_HighAllocName(unsigned int size, char *name) {
|
|
||||||
|
|
||||||
hunk_t *h;
|
|
||||||
unsigned int freespace;
|
|
||||||
unsigned int totalsize = sizeof(hunk_t) + ((size+15)&~15);
|
|
||||||
|
|
||||||
if(sg_hunk_tempactive) {
|
|
||||||
|
|
||||||
Hunk_FreeToHighMark(sg_hunk_tempmark);
|
|
||||||
sg_hunk_tempactive = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
freespace = sg_hunk_size - sg_hunk_low_used - sg_hunk_high_used;
|
|
||||||
|
|
||||||
if(totalsize < size || totalsize > freespace) { //overflow catching
|
|
||||||
Con_Printf("Hunk_HighAllocName: Requested size %u, padded to size %u, total free hunk is %u", size, totalsize, freespace);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
sg_hunk_high_used += size;
|
|
||||||
Cache_FreeHigh(sg_hunk_high_used);
|
|
||||||
|
|
||||||
h = (hunk_t *)(sg_hunk_base + sg_hunk_size - sg_hunk_high_used);
|
|
||||||
|
|
||||||
memset(h, 0, size);
|
|
||||||
h->size = size;
|
|
||||||
h->sentinal = HUNK_SENTINAL;
|
|
||||||
Q_strncpy(h->name, name, HUNK_ARRAYNAMELENGTH-1);
|
|
||||||
|
|
||||||
return(void *)(h+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_Low/HighMark
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH:
|
|
||||||
//
|
|
||||||
// Return some global vars.
|
|
||||||
*/
|
|
||||||
uint32 Hunk_LowMark(void) {
|
|
||||||
|
|
||||||
return(sg_hunk_low_used);
|
|
||||||
}
|
|
||||||
uint32 Hunk_HighMark(void) {
|
|
||||||
|
|
||||||
if(sg_hunk_tempactive) {
|
|
||||||
|
|
||||||
sg_hunk_tempactive = 0;
|
|
||||||
Hunk_FreeToHighMark(sg_hunk_tempmark);
|
|
||||||
}
|
|
||||||
return(sg_hunk_high_used);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_FreeToLowMark
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Some host and mod thing
|
|
||||||
//
|
|
||||||
// reassigns some variables. We zero the memory out; HL doesn't seem to care.
|
|
||||||
*/
|
|
||||||
void Hunk_FreeToLowMark(unsigned int mark) {
|
|
||||||
|
|
||||||
if (mark > sg_hunk_low_used) {
|
|
||||||
Sys_Error ("Hunk_FreeToLowMark: bad mark %i", mark);
|
|
||||||
}
|
|
||||||
memset(sg_hunk_base + mark, 0, sg_hunk_low_used - mark);
|
|
||||||
sg_hunk_low_used = mark;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_FreeToHighMark
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Other hunk functions
|
|
||||||
//
|
|
||||||
// This seems to mostly be used for clearing up the temp allocation. Anything
|
|
||||||
// between the high stack's current position and the desired mark--an area not
|
|
||||||
// used for much--is wiped clean.
|
|
||||||
*/
|
|
||||||
void Hunk_FreeToHighMark(unsigned int mark) {
|
|
||||||
|
|
||||||
if (sg_hunk_tempactive) {
|
|
||||||
sg_hunk_tempactive = 0;
|
|
||||||
Hunk_FreeToHighMark (sg_hunk_tempmark);
|
|
||||||
}
|
|
||||||
if (mark > sg_hunk_high_used) {
|
|
||||||
Sys_Error("Hunk_FreeToHighMark: bad mark %i", mark);
|
|
||||||
}
|
|
||||||
memset(sg_hunk_base + sg_hunk_size - sg_hunk_high_used, 0, sg_hunk_high_used - mark);
|
|
||||||
sg_hunk_high_used = mark;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_Check
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: nowhere yet
|
|
||||||
//
|
|
||||||
// Makes sure the sentinel is intact
|
|
||||||
*/
|
|
||||||
void Hunk_Check(void) {
|
|
||||||
|
|
||||||
hunk_t *h;
|
|
||||||
|
|
||||||
for (h = (hunk_t *)sg_hunk_base; (byte *)h < sg_hunk_base + sg_hunk_low_used; h = (hunk_t *)((byte *)h+h->size)) {
|
|
||||||
if (h->sentinal != HUNK_SENTINAL) {
|
|
||||||
Sys_Error("Hunk_Check: trashed sentinal at address %p. If the name isn't trashed too, it's %s.", h, h->name);
|
|
||||||
}
|
|
||||||
if ((h->size && 15) != 0 || h->size + (unsigned)(byte *)h - (unsigned)sg_hunk_base > sg_hunk_size) {
|
|
||||||
Sys_Error("Hunk_Check: bad size");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Hunk_Print
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: nowhere
|
|
||||||
//
|
|
||||||
// nothing
|
|
||||||
*/
|
|
||||||
void Hunk_Print(/*qboolean ignored*/) {
|
|
||||||
|
|
||||||
Con_Printf("Hunk_Print called, then ignored.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** CACHE ***/
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_Init
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: This File: Memory_Init->Cache_Init
|
|
||||||
//
|
|
||||||
// It looks like it simply adds console commands and zeros out some global structure
|
|
||||||
*/
|
|
||||||
void Cache_Init() {
|
|
||||||
|
|
||||||
sg_cache_head.next = sg_cache_head.prev = sg_cache_head.lru_next = sg_cache_head.lru_prev = &sg_cache_head;
|
|
||||||
Cmd_AddCommand("flush", Cache_Flush);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_Alloc
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Mod and other places not in this file
|
|
||||||
//
|
|
||||||
// Gets a bit of the hunk. Most of the work is done in tryalloc.
|
|
||||||
*/
|
|
||||||
void *Cache_Alloc(cache_user_t *c, unsigned int size, const char *name) {
|
|
||||||
|
|
||||||
cache_system_t *cs;
|
|
||||||
|
|
||||||
|
|
||||||
if(c->data) {
|
|
||||||
Sys_Error("Cache_Alloc: already allocated");
|
|
||||||
}
|
|
||||||
if(size <= 0) {
|
|
||||||
Sys_Error("Cache_Alloc: size is either SO LARGE IT WRAPPED AROUND or zero.", size);
|
|
||||||
}
|
|
||||||
size = (size + sizeof(cache_system_t) + 15) & ~15;
|
|
||||||
|
|
||||||
//Took me a bit; the whole 'add 15 not 15' thing is to ensure this lines up on a 16 byte boundary
|
|
||||||
|
|
||||||
// find memory for it
|
|
||||||
while(1) {
|
|
||||||
cs = Cache_TryAlloc(size, 0);
|
|
||||||
|
|
||||||
if(cs) { //hooray, we found room
|
|
||||||
Q_strncpy(cs->name, name, sizeof(cs->name)-1);
|
|
||||||
c->data = (void *)(cs+1);
|
|
||||||
cs->user = c;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We didn't find room, free something and try again
|
|
||||||
if(sg_cache_head.lru_prev == &sg_cache_head) { //nothing left to free
|
|
||||||
Sys_Error("Cache_Alloc: out of memory");
|
|
||||||
}
|
|
||||||
Cache_Free(sg_cache_head.lru_prev->user);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(Cache_Check(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_TryAlloc
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Cache_Move || Cache_Alloc ->Cache_TryAlloc
|
|
||||||
//
|
|
||||||
// From zone.c: Looks for a free block of memory between the high and low
|
|
||||||
// hunk marks. Size should already include the header and padding
|
|
||||||
*/
|
|
||||||
cache_system_t *Cache_TryAlloc (unsigned int size, qboolean nobottom) {
|
|
||||||
cache_system_t *cs, *newc;
|
|
||||||
|
|
||||||
// unique case 1: Cache is completely unused
|
|
||||||
if (nobottom == 0 && sg_cache_head.prev == &sg_cache_head) {
|
|
||||||
|
|
||||||
//if they want more room than we have period then they need to fix their code
|
|
||||||
if (sg_hunk_size - sg_hunk_high_used - sg_hunk_low_used < size) {
|
|
||||||
Sys_Error("Cache_TryAlloc: %i is greater then the possibly empty hunk", size);
|
|
||||||
} else {
|
|
||||||
newc = (cache_system_t *) (sg_hunk_base + sg_hunk_low_used);
|
|
||||||
memset (newc, 0, sizeof(*newc));
|
|
||||||
newc->size = size;
|
|
||||||
|
|
||||||
sg_cache_head.prev = sg_cache_head.next = newc;
|
|
||||||
newc->prev = newc->next = &sg_cache_head;
|
|
||||||
|
|
||||||
Cache_MakeLRU (newc);
|
|
||||||
return(newc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// search from the bottom up for space
|
|
||||||
|
|
||||||
newc = (cache_system_t *) (sg_hunk_base + sg_hunk_low_used);
|
|
||||||
cs = sg_cache_head.next;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (nobottom == 0 || cs != sg_cache_head.next) {
|
|
||||||
if ( (unsigned)(byte *)cs - (unsigned)(byte *)newc >= size) {
|
|
||||||
|
|
||||||
// found space
|
|
||||||
memset (newc, 0, sizeof(*newc));
|
|
||||||
newc->size = size;
|
|
||||||
|
|
||||||
newc->next = cs;
|
|
||||||
newc->prev = cs->prev;
|
|
||||||
cs->prev->next = newc;
|
|
||||||
cs->prev = newc;
|
|
||||||
|
|
||||||
Cache_MakeLRU (newc);
|
|
||||||
|
|
||||||
return(newc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise continue looking
|
|
||||||
newc = (cache_system_t *)((byte *)cs + cs->size);
|
|
||||||
cs = cs->next;
|
|
||||||
|
|
||||||
} while (cs != &sg_cache_head);
|
|
||||||
|
|
||||||
// We either failed or ignored all the area at the beginning. We must now try
|
|
||||||
// to allocate room right at the end of thi patchwork memory model.
|
|
||||||
|
|
||||||
if ((unsigned)sg_hunk_base + sg_hunk_size - sg_hunk_high_used - (unsigned)(byte *)newc >= size) {
|
|
||||||
|
|
||||||
memset (newc, 0, sizeof(*newc));
|
|
||||||
newc->size = size;
|
|
||||||
|
|
||||||
newc->next = &sg_cache_head;
|
|
||||||
newc->prev = sg_cache_head.prev;
|
|
||||||
sg_cache_head.prev->next = newc;
|
|
||||||
sg_cache_head.prev = newc;
|
|
||||||
|
|
||||||
Cache_MakeLRU (newc);
|
|
||||||
|
|
||||||
return(newc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(NULL); // couldn't allocate
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_MakeLRU
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Cache_TryAlloc (or check)->Cache_MakeLRU
|
|
||||||
//
|
|
||||||
// Adds this thing to a linked list, and aborts if it's already added
|
|
||||||
// Don't really know what makes the LRU list so special.
|
|
||||||
*/
|
|
||||||
void Cache_MakeLRU (cache_system_t *cs) {
|
|
||||||
|
|
||||||
if ((cs->lru_next != NULL) || (cs->lru_prev != NULL)) {
|
|
||||||
Sys_Error("Cache_MakeLRU: already linked, aborting");
|
|
||||||
}
|
|
||||||
sg_cache_head.lru_next->lru_prev = cs;
|
|
||||||
cs->lru_next = sg_cache_head.lru_next;
|
|
||||||
cs->lru_prev = &sg_cache_head;
|
|
||||||
sg_cache_head.lru_next = cs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_UnlinkLRU
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Cache_functions->Cache_UnlinkLRU
|
|
||||||
//
|
|
||||||
// The exact opposite of the above.
|
|
||||||
*/
|
|
||||||
void Cache_UnlinkLRU (cache_system_t *cs) {
|
|
||||||
|
|
||||||
if (!cs->lru_next || !cs->lru_prev) {
|
|
||||||
Sys_Error("Cache_UnlinkLRU: Not linked, aborting");
|
|
||||||
}
|
|
||||||
cs->lru_next->lru_prev = cs->lru_prev;
|
|
||||||
cs->lru_prev->lru_next = cs->lru_next;
|
|
||||||
|
|
||||||
cs->lru_prev = cs->lru_next = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_Check
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: All over
|
|
||||||
//
|
|
||||||
// Just verifies that the data is there I guess... Moves it too.
|
|
||||||
*/
|
|
||||||
HLDS_DLLEXPORT void * Cache_Check(cache_user_t *c) {
|
|
||||||
cache_system_t * cs;
|
|
||||||
|
|
||||||
if (!c->data)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
cs = ((cache_system_t *)c->data) - 1;
|
|
||||||
//cs = (cache_system_t *)(((byte *)c->data) - ((int)&(((cache_system_t *)0)->user)));
|
|
||||||
|
|
||||||
// move to head of LRU
|
|
||||||
Cache_UnlinkLRU(cs);
|
|
||||||
Cache_MakeLRU(cs);
|
|
||||||
|
|
||||||
return(c->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_Move
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Cache_FreeLow || Cache_FreeHigh
|
|
||||||
//
|
|
||||||
// Well the name describes what it does better than I can. I don't quite
|
|
||||||
// see right now why 'moving' takes this much effort though.
|
|
||||||
*/
|
|
||||||
void Cache_Move(cache_system_t *c) {
|
|
||||||
cache_system_t *newc;
|
|
||||||
|
|
||||||
// we are clearing up space at the bottom, so only allocate it late
|
|
||||||
newc = Cache_TryAlloc(c->size, 1);
|
|
||||||
|
|
||||||
if(newc) {
|
|
||||||
|
|
||||||
Q_memcpy ( newc+1, c+1, c->size - sizeof(cache_system_t) );
|
|
||||||
newc->user = c->user;
|
|
||||||
Q_memcpy (newc->name, c->name, sizeof(newc->name));
|
|
||||||
Cache_Free (c->user);
|
|
||||||
newc->user->data = (void *)(newc+1);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
Cache_Free (c->user); // tough luck
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_Flush
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Called dynamically when "flush" console command is used
|
|
||||||
//
|
|
||||||
// In asm, this is long and boring and calls cache_force_flush. In QW, this
|
|
||||||
// has been replaced with a nicer set of functions that I think can be used w/o worry.
|
|
||||||
*/
|
|
||||||
void Cache_Flush() {
|
|
||||||
|
|
||||||
while(&sg_cache_head != sg_cache_head.next) {
|
|
||||||
Cache_Free(sg_cache_head.next->user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_Free
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Many places besides this file
|
|
||||||
//
|
|
||||||
// Let My Memory Go (and remove it from the active list)
|
|
||||||
*/
|
|
||||||
void Cache_Free(cache_user_t *c) {
|
|
||||||
|
|
||||||
cache_system_t *cs;
|
|
||||||
|
|
||||||
if (!c->data) {
|
|
||||||
Sys_Error("Cache_Free: not allocated");
|
|
||||||
}
|
|
||||||
cs = ((cache_system_t *)c->data) - 1; //+FFFFFFA8?
|
|
||||||
|
|
||||||
cs->prev->next = cs->next;
|
|
||||||
cs->next->prev = cs->prev;
|
|
||||||
cs->next = cs->prev = NULL;
|
|
||||||
|
|
||||||
c->data = NULL;
|
|
||||||
|
|
||||||
Cache_UnlinkLRU(cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Cache_FreeLow/High
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Hunk_(High)AllocName->Cache_FreeLow/High
|
|
||||||
//
|
|
||||||
// Frees up memory so we can squeeze something new in
|
|
||||||
*/
|
|
||||||
void Cache_FreeLow(unsigned int new_low_hunk) {
|
|
||||||
cache_system_t *c;
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
|
|
||||||
c = sg_cache_head.next;
|
|
||||||
if(c == &sg_cache_head) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if((byte *)c >= sg_hunk_base + new_low_hunk) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Cache_Move(c); // reclaim the space
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void Cache_FreeHigh(unsigned int new_high_hunk) {
|
|
||||||
|
|
||||||
cache_system_t *c, *prev;
|
|
||||||
|
|
||||||
prev = NULL;
|
|
||||||
while (1) {
|
|
||||||
|
|
||||||
c = sg_cache_head.prev;
|
|
||||||
if (c == &sg_cache_head) { //nothing cached
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((byte *)c + c->size <= sg_hunk_base + sg_hunk_size - new_high_hunk) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (c == prev) {
|
|
||||||
Cache_Free(c->user); // didn't move out of the way
|
|
||||||
} else {
|
|
||||||
Cache_Move(c); // try to move it
|
|
||||||
prev = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* UNIMPLEMENTED: CacheSystemCompare
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: Passed as an argument to qsort, local to HUNK status functions
|
|
||||||
//
|
|
||||||
// Using strcmp, compares--get this--the names of two cache_system_t
|
|
||||||
// objects. I'm pretty certain it's a straight Q_strcasecmp with no added
|
|
||||||
// trickery and definitely no modification of variables.
|
|
||||||
//
|
|
||||||
// But it's not necessary, and therefore won't be used in the finished product.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//reporting is for chumps. I won't be sorting or doing fancy crap cause it's not
|
|
||||||
//vital to a running server.
|
|
||||||
void Cache_TotalUsed() {
|
|
||||||
Con_Printf("CacheTotal: Go away.\n");
|
|
||||||
}
|
|
||||||
void Cache_Report() {
|
|
||||||
Con_Printf("%4.1f megabyte data cache\n", (sg_hunk_size - sg_hunk_high_used - sg_hunk_low_used) / (float)(1024*1024) );
|
|
||||||
}
|
|
||||||
void Cache_Print () {
|
|
||||||
|
|
||||||
Con_Printf("Cache_Print: I thought the linux build didn't include these debug things. Stop calling them.\n");
|
|
||||||
}
|
|
||||||
void Cache_Print_Models_And_Totals() {
|
|
||||||
Con_Printf("Cache_Print_models: No, you can't haev a stats update. Not yours.\n");
|
|
||||||
}
|
|
||||||
void Cache_Print_Sounds_And_Totals() {
|
|
||||||
Con_Printf("Cache_Print_Sounds: Debug statements annoy me.\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** Z ***/
|
|
||||||
|
|
||||||
/* DESCRIPTION: Z_ClearZone
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: Memory_Init->Z_ClearZone
|
|
||||||
//
|
|
||||||
// An init function, basically.
|
|
||||||
*/
|
|
||||||
void Z_ClearZone(memzone_t *zone, unsigned int size) {
|
|
||||||
memblock_t *block;
|
|
||||||
|
|
||||||
// set the entire zone to one free block
|
|
||||||
|
|
||||||
zone->blocklist.next = zone->blocklist.prev = block = (memblock_t *)( (byte *)zone + sizeof(memzone_t) );
|
|
||||||
zone->blocklist.tag = 1; // in use block
|
|
||||||
zone->blocklist.id = 0;
|
|
||||||
zone->blocklist.size = 0;
|
|
||||||
zone->rover = block;
|
|
||||||
|
|
||||||
block->prev = block->next = &zone->blocklist;
|
|
||||||
block->tag = 0; // free block
|
|
||||||
block->id = ZONEID;
|
|
||||||
block->size = size - sizeof(memzone_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Z_Free
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: all over
|
|
||||||
//
|
|
||||||
// Frees a Z block, marking it as such
|
|
||||||
*/
|
|
||||||
void Z_Free(void *ptr) {
|
|
||||||
|
|
||||||
memblock_t *block, *other;
|
|
||||||
|
|
||||||
if (!ptr) {
|
|
||||||
Sys_Error("Z_Free: NULL pointer");
|
|
||||||
}
|
|
||||||
|
|
||||||
block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
|
|
||||||
if (block->id != ZONEID) {
|
|
||||||
Sys_Error ("Z_Free: freed a pointer without ZONEID");
|
|
||||||
}
|
|
||||||
if (block->tag == 0) {
|
|
||||||
Sys_Error ("Z_Free: freed a freed pointer");
|
|
||||||
}
|
|
||||||
block->tag = 0; // mark as free
|
|
||||||
|
|
||||||
other = block->prev;
|
|
||||||
if (!other->tag) { // merge with previous free block
|
|
||||||
other->size += block->size;
|
|
||||||
other->next = block->next;
|
|
||||||
other->next->prev = other;
|
|
||||||
if (block == sg_mainzone->rover) {
|
|
||||||
sg_mainzone->rover = other;
|
|
||||||
}
|
|
||||||
block = other;
|
|
||||||
}
|
|
||||||
|
|
||||||
other = block->next;
|
|
||||||
if (!other->tag) { // merge the next free block onto the end
|
|
||||||
block->size += other->size;
|
|
||||||
block->next = other->next;
|
|
||||||
block->next->prev = block;
|
|
||||||
if (other == sg_mainzone->rover) {
|
|
||||||
sg_mainzone->rover = block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Z_Malloc
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: all over
|
|
||||||
//
|
|
||||||
// Assigns a Z block
|
|
||||||
*/
|
|
||||||
void *Z_Malloc(unsigned int size) {
|
|
||||||
|
|
||||||
void *buf;
|
|
||||||
|
|
||||||
Z_CheckHeap();
|
|
||||||
buf = Z_TagMalloc(size, 1);
|
|
||||||
if (!buf) {
|
|
||||||
Sys_Error("Z_Malloc: failed on allocation of %i bytes",size);
|
|
||||||
}
|
|
||||||
Q_memset(buf, 0, size);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Z_TagMalloc
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: all over
|
|
||||||
//
|
|
||||||
// Does the actual assigning. To be honest, this Z stuff seems weak. Do not want.
|
|
||||||
*/
|
|
||||||
void *Z_TagMalloc(unsigned int size, int tag) {
|
|
||||||
|
|
||||||
int extra;
|
|
||||||
memblock_t *start, *rover, *newz, *base;
|
|
||||||
|
|
||||||
if (tag == 0) {
|
|
||||||
Sys_Error ("Z_TagMalloc: tried to use a 0 tag");
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// scan through the block list looking for the first free block
|
|
||||||
// of sufficient size
|
|
||||||
//
|
|
||||||
size += sizeof(memblock_t); // account for size of block header
|
|
||||||
size += 4; // space for memory trash tester
|
|
||||||
size = (size + 7) & ~7; // align to 8-qbyte boundary
|
|
||||||
|
|
||||||
base = rover = sg_mainzone->rover;
|
|
||||||
start = base->prev;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (rover == start) { // scanned all the way around the list
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
if (rover->tag) {
|
|
||||||
base = rover = rover->next;
|
|
||||||
} else {
|
|
||||||
rover = rover->next;
|
|
||||||
}
|
|
||||||
} while (base->tag || base->size < size);
|
|
||||||
|
|
||||||
//
|
|
||||||
// found a block big enough
|
|
||||||
//
|
|
||||||
extra = base->size - size;
|
|
||||||
if (extra > MINFRAGMENT) { // there will be a free fragment after the allocated block
|
|
||||||
newz = (memblock_t *) ((byte *)base + size );
|
|
||||||
newz->size = extra;
|
|
||||||
newz->tag = 0; // free block
|
|
||||||
newz->prev = base;
|
|
||||||
newz->id = ZONEID;
|
|
||||||
newz->next = base->next;
|
|
||||||
newz->next->prev = newz;
|
|
||||||
base->next = newz;
|
|
||||||
base->size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
base->tag = tag; // no longer a free block
|
|
||||||
|
|
||||||
sg_mainzone->rover = base->next; // next allocation will start looking here
|
|
||||||
|
|
||||||
base->id = ZONEID;
|
|
||||||
|
|
||||||
// marker for memory trash testing
|
|
||||||
*(int *)((byte *)base + base->size - 4) = ZONEID;
|
|
||||||
|
|
||||||
return (void *) ((byte *)base + sizeof(memblock_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Z_Print
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: nowhere
|
|
||||||
//
|
|
||||||
// Prints the lovely stuff. Or as I do, prints nothing and calls it a day.
|
|
||||||
*/
|
|
||||||
void Z_Print(/*memzone_t *zone*/) {
|
|
||||||
|
|
||||||
Con_Printf ("Z_Print called, then ignored.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: Z_CheckHeap
|
|
||||||
// LOCATION: zone.c
|
|
||||||
// PATH: nowhere
|
|
||||||
//
|
|
||||||
// For some reason this statement that would probably be def'd out is in the executable.
|
|
||||||
// Just makes sure it's all up to snuff.
|
|
||||||
*/
|
|
||||||
void Z_CheckHeap(void) {
|
|
||||||
|
|
||||||
memblock_t *block;
|
|
||||||
|
|
||||||
for (block = sg_mainzone->blocklist.next; ; block = block->next) {
|
|
||||||
if (block->next == &sg_mainzone->blocklist) {
|
|
||||||
break; // all blocks have been hit
|
|
||||||
}
|
|
||||||
if ( (byte *)block + block->size != (byte *)block->next) {
|
|
||||||
Sys_Error("Z_CheckHeap: block size does not touch the next block\n");
|
|
||||||
}
|
|
||||||
if ( block->next->prev != block) {
|
|
||||||
Sys_Error("Z_CheckHeap: next block doesn't have proper back link\n");
|
|
||||||
}
|
|
||||||
if (!block->tag && !block->next->tag) {
|
|
||||||
Sys_Error("Z_CheckHeap: two consecutive free blocks\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* Rather than malloc and free every which way, the HUNK carves out
|
|
||||||
// a huge chunk of RAM from the get go and doles it out as needed.
|
|
||||||
// This is nice in that it prevents malloc failures later on and
|
|
||||||
// eased the burden on those more limited systems. This is BAD because
|
|
||||||
// their memory functions aren't bug free (QW had a few changes), and
|
|
||||||
// because while everyone knows how malloc works, the same can't be said
|
|
||||||
// for hunks.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_ENGINE_HEADER
|
|
||||||
#define OSHLDS_ENGINE_HEADER
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "Q_memdef.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
|
|
||||||
/*** structures ***/
|
|
||||||
|
|
||||||
//doesn't belong here, but it works pretty well, and I don't have a better spot
|
|
||||||
typedef struct cache_user_s {
|
|
||||||
byte *data;
|
|
||||||
} cache_user_t;
|
|
||||||
|
|
||||||
|
|
||||||
/*** PUBLIC FUNCTIONS ***/
|
|
||||||
|
|
||||||
//mem
|
|
||||||
void Memory_Init(void *, unsigned int);
|
|
||||||
|
|
||||||
uint32 Hunk_LowMark(void);
|
|
||||||
uint32 Hunk_HighMark(void);
|
|
||||||
void Hunk_FreeToLowMark(unsigned int mark);
|
|
||||||
void Hunk_FreeToHighMark(unsigned int mark);
|
|
||||||
|
|
||||||
void * Hunk_Alloc(unsigned int);
|
|
||||||
void * Hunk_AllocName(unsigned int, const char *);
|
|
||||||
void * Hunk_TempAlloc(unsigned int);
|
|
||||||
|
|
||||||
void * Cache_Alloc(cache_user_t *, unsigned int, const char *);
|
|
||||||
HLDS_DLLEXPORT void * Cache_Check(cache_user_t *);
|
|
||||||
void Cache_Free(cache_user_t *);
|
|
||||||
|
|
||||||
void * Z_Malloc(unsigned int);
|
|
||||||
void Z_Free(void *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
So far I've added two libraries: Boost, for the filesystem, and cprops for AVL trees. Both libraries provide much more, but that's all I require.
|
|
||||||
|
|
||||||
Boost is fairly complicated to install and use. Its inclusion is something I somewhat regret; I might've been better off using something else, as Boost and I are often at odds. Unfortunately, there really aren't a lot of good portable file lobs, and I really didn't want to write my own.
|
|
||||||
|
|
||||||
cprops offers a lot of nifty things, and I like it. It's much easier for me to modify than boost, and its style of design is close to what I myself use. Right now, I'm only using the avl trees. It might--at some other date--be prudent to gut the library and remove all of the things I never plan on using. But right now it doesn't hurt much, so I'll leave it alone. The only problem with cprops is it's desuigned for unix OR VS on Windows, and not MingW. Because of this, some of the defines and configurations needed reworking. They are minor, but they are enough to warn you about.
|
|
||||||
At the moment, to use the AVL trees, only the files "avl.c collection.c mempool.c rb.c vector.c" need to be compiled. If you have problems compiling any other files, then don't compile them.
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,740 +0,0 @@
|
|||||||
/* Relates to MODELS, not MODIFICATIONS. QW has extensive examples here.
|
|
||||||
*/
|
|
||||||
#ifndef OSHLDS_MODEL_HEADER
|
|
||||||
#define OSHLDS_MODEL_HEADER
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "HUNK.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
|
|
||||||
// d* structures refer to how something is stored in a file
|
|
||||||
// m* structs refer to how it is stored in memory.
|
|
||||||
// Some of them may be backwards, and a lot of these may be unused.
|
|
||||||
|
|
||||||
//Several of these structs have cross dependencies, which must be resolved
|
|
||||||
//by NOT using the typedef'd name.
|
|
||||||
|
|
||||||
//Many of these structs can and probably should go into the code instead of the header.
|
|
||||||
|
|
||||||
#define MAX_MAP_HULLSDQ1 4
|
|
||||||
#define MAX_MAP_HULLSDH2 8
|
|
||||||
#define MAX_MAP_HULLSM 16
|
|
||||||
|
|
||||||
#define MAX_MAP_MODELS 256
|
|
||||||
#define MAX_MAP_BRUSHES 0x8000
|
|
||||||
#define MAX_MAP_ENTITIES 1024
|
|
||||||
#define MAX_MAP_ENTSTRING 65536
|
|
||||||
|
|
||||||
#define MAX_MAP_PLANES 65636*2
|
|
||||||
#define MAX_MAP_NODES 65535
|
|
||||||
#define MAX_MAP_CLIPNODES 65535
|
|
||||||
#define MAX_MAP_LEAFS 65535
|
|
||||||
#define MAX_MAP_VERTS 65535
|
|
||||||
#define MAX_MAP_FACES 65535
|
|
||||||
#define MAX_MAP_MARKSURFACES 65535
|
|
||||||
#define MAX_MAP_TEXINFO 4096
|
|
||||||
#define MAX_MAP_EDGES 256000
|
|
||||||
#define MAX_MAP_SURFEDGES 512000
|
|
||||||
#define MAX_MAP_MIPTEX 0x200000
|
|
||||||
#define MAX_MAP_LIGHTING 0x100000
|
|
||||||
#define MAX_MAP_VISIBILITY 0x200000
|
|
||||||
|
|
||||||
// key / value pair sizes
|
|
||||||
|
|
||||||
#define MAX_KEY 32
|
|
||||||
#define MAX_VALUE 1024
|
|
||||||
|
|
||||||
|
|
||||||
#define LUMP_ENTITIES 0
|
|
||||||
#define LUMP_PLANES 1
|
|
||||||
#define LUMP_TEXTURES 2
|
|
||||||
#define LUMP_VERTEXES 3
|
|
||||||
#define LUMP_VISIBILITY 4
|
|
||||||
#define LUMP_NODES 5
|
|
||||||
#define LUMP_TEXINFO 6
|
|
||||||
#define LUMP_FACES 7
|
|
||||||
#define LUMP_LIGHTING 8
|
|
||||||
#define LUMP_CLIPNODES 9
|
|
||||||
#define LUMP_LEAFS 10
|
|
||||||
#define LUMP_MARKSURFACES 11
|
|
||||||
#define LUMP_EDGES 12
|
|
||||||
#define LUMP_SURFEDGES 13
|
|
||||||
#define LUMP_MODELS 14
|
|
||||||
|
|
||||||
#define HEADER_LUMPS 15
|
|
||||||
|
|
||||||
typedef enum { ST_SYNC=0, ST_RAND } synctype_t;
|
|
||||||
typedef enum { ALIAS_SINGLE=0, ALIAS_GROUP, ALIAS_GROUP_SWAPPED = 16777216 } aliasframetype_t;
|
|
||||||
typedef enum { ALIAS_SKIN_SINGLE=0, ALIAS_SKIN_GROUP } aliasskintype_t;
|
|
||||||
typedef enum { SPR_SINGLE=0, SPR_GROUP, SPR_ANGLED } spriteframetype_t;
|
|
||||||
|
|
||||||
|
|
||||||
/*** STRUCTS ***/
|
|
||||||
|
|
||||||
typedef struct lump_s {
|
|
||||||
int fileofs, filelen;
|
|
||||||
} lump_t;
|
|
||||||
typedef struct dheader_s { //no counterpart
|
|
||||||
int version;
|
|
||||||
lump_t lumps[HEADER_LUMPS];
|
|
||||||
} dheader_t;
|
|
||||||
typedef struct dmiptexlump_s { //0x14 //no counterpart
|
|
||||||
|
|
||||||
int nummiptex;
|
|
||||||
int dataofs[4]; // [nummiptex]
|
|
||||||
} dmiptexlump_t;
|
|
||||||
|
|
||||||
typedef struct dnode_s {
|
|
||||||
|
|
||||||
int planenum;
|
|
||||||
short children[2]; // negative numbers are -(leafs+1), not nodes
|
|
||||||
short mins[3]; // for sphere culling
|
|
||||||
short maxs[3];
|
|
||||||
unsigned short firstface;
|
|
||||||
unsigned short numfaces; // counting both sides
|
|
||||||
} dnode_t;
|
|
||||||
typedef struct mnode_s {
|
|
||||||
|
|
||||||
// common with leaf
|
|
||||||
int contents; // 0, to differentiate from leafs
|
|
||||||
int visframe; // node needs to be traversed if current
|
|
||||||
|
|
||||||
short minmaxs[6]; // for bounding box culling
|
|
||||||
|
|
||||||
struct mnode_s *parent;
|
|
||||||
|
|
||||||
// node specific
|
|
||||||
struct mplane_s *plane;
|
|
||||||
struct mnode_s *children[2]; //1c
|
|
||||||
|
|
||||||
unsigned short firstsurface; //24
|
|
||||||
unsigned short numsurfaces;
|
|
||||||
} mnode_t;
|
|
||||||
|
|
||||||
#define NUM_AMBIENTS 4
|
|
||||||
typedef struct dleaf_s {
|
|
||||||
|
|
||||||
int contents;
|
|
||||||
int visofs; // -1 = no visibility info
|
|
||||||
|
|
||||||
short mins[3]; // for frustum culling
|
|
||||||
short maxs[3];
|
|
||||||
|
|
||||||
unsigned short firstmarksurface;
|
|
||||||
unsigned short nummarksurfaces;
|
|
||||||
|
|
||||||
byte ambient_level[NUM_AMBIENTS];
|
|
||||||
} dleaf_t;
|
|
||||||
typedef struct mleaf_s { //0x30
|
|
||||||
|
|
||||||
// common with node
|
|
||||||
int contents; // wil be a negative contents number
|
|
||||||
int visframe; // node needs to be traversed if current
|
|
||||||
|
|
||||||
short minmaxs[6]; // for bounding box culling
|
|
||||||
|
|
||||||
struct mnode_s *parent;
|
|
||||||
|
|
||||||
// leaf specific
|
|
||||||
byte *compressed_vis; //18
|
|
||||||
struct efrag_s *efrags;
|
|
||||||
|
|
||||||
struct msurface_s **firstmarksurface;
|
|
||||||
int nummarksurfaces;
|
|
||||||
int key; // BSP sequence number for leaf's contents
|
|
||||||
byte ambient_sound_level[4];
|
|
||||||
} mleaf_t;
|
|
||||||
|
|
||||||
typedef struct plane_s { //0x10 pmplane
|
|
||||||
|
|
||||||
vec3_t normal;
|
|
||||||
float dist;
|
|
||||||
} plane_t;
|
|
||||||
typedef struct cplane_s {//0x14
|
|
||||||
|
|
||||||
vec3_t normal;
|
|
||||||
float dist;
|
|
||||||
int type;
|
|
||||||
} cplane_t;
|
|
||||||
typedef struct mplane_s { //sizeof 0x14
|
|
||||||
|
|
||||||
vec3_t normal; //00
|
|
||||||
float dist; //0c, sounds right.
|
|
||||||
byte type; //10 // for texture axis selection and fast side tests
|
|
||||||
byte signbits; // signx + signy<<1 + signz<<1
|
|
||||||
byte pad[2];
|
|
||||||
} mplane_t;
|
|
||||||
|
|
||||||
typedef struct dclipnode_s { //sixeof 0x08
|
|
||||||
|
|
||||||
int planenum;
|
|
||||||
short children[2]; // negative numbers are contents
|
|
||||||
} dclipnode_t;
|
|
||||||
typedef struct hull_s { //sizeof 0x28
|
|
||||||
|
|
||||||
dclipnode_t * clipnodes;
|
|
||||||
mplane_t * planes;
|
|
||||||
int firstclipnode;
|
|
||||||
int lastclipnode;
|
|
||||||
vec3_t clip_mins;
|
|
||||||
vec3_t clip_maxs;
|
|
||||||
} hull_t;
|
|
||||||
|
|
||||||
typedef struct dvertex_s {
|
|
||||||
float point[3];
|
|
||||||
} dvertex_t;
|
|
||||||
typedef struct mvertex_s { //same thing, different 'naming'.
|
|
||||||
vec3_t position;
|
|
||||||
} mvertex_t;
|
|
||||||
|
|
||||||
typedef struct dedge_s {
|
|
||||||
unsigned short v[2]; // vertex numbers
|
|
||||||
} dedge_t;
|
|
||||||
typedef struct medge_s {
|
|
||||||
unsigned short v[2];
|
|
||||||
unsigned int cachededgeoffset;
|
|
||||||
} medge_t;
|
|
||||||
|
|
||||||
typedef struct color24_s {
|
|
||||||
byte r, g, b;
|
|
||||||
} color24_t;
|
|
||||||
typedef struct colorVec_s {
|
|
||||||
unsigned long int r, g, b, a;
|
|
||||||
} colorVec_t;
|
|
||||||
typedef struct PackedColorVec_s {
|
|
||||||
unsigned short int r, g, b, a;
|
|
||||||
} PackedColorVec_t;
|
|
||||||
|
|
||||||
typedef struct texture_s {
|
|
||||||
|
|
||||||
char name[16]; //00
|
|
||||||
unsigned width, height; //10
|
|
||||||
int anim_total; //18 // total tenths in sequence ( 0 = no)
|
|
||||||
int anim_min, anim_max; //1C // time for this frame min <=time< max
|
|
||||||
struct texture_s * anim_next; //24 // in the animation sequence
|
|
||||||
struct texture_s * alternate_anims; //28 // bmodels in frame 1 use these
|
|
||||||
unsigned offsets[4]; //2c // four mip maps stored
|
|
||||||
unsigned paloffset; //3c
|
|
||||||
} texture_t;
|
|
||||||
|
|
||||||
typedef struct dtexinfo_s {
|
|
||||||
float vecs[2][4]; // [s/t][xyz offset]
|
|
||||||
int miptex;
|
|
||||||
int flags;
|
|
||||||
} dtexinfo_t;
|
|
||||||
typedef struct mtexinfo_s {
|
|
||||||
|
|
||||||
float vecs[2][4]; // [s/t] unit vectors in world space.
|
|
||||||
// [i][3] is the s/t offset relative to the origin.
|
|
||||||
// s or t = dot(3Dpoint,vecs[i])+vecs[i][3]
|
|
||||||
float mipadjust; // ?? mipmap limits for very small surfaces
|
|
||||||
texture_t * texture;
|
|
||||||
int flags; // sky or slime, no lightmap or 256 subdivision
|
|
||||||
} mtexinfo_t;
|
|
||||||
|
|
||||||
typedef struct msurface_s {
|
|
||||||
|
|
||||||
int visframe; // should be drawn when node is crossed
|
|
||||||
int dlightframe; // last frame the surface was checked by an animated light
|
|
||||||
int dlightbits; // dynamically generated. Indicates if the surface illumination
|
|
||||||
// is modified by an animated light.
|
|
||||||
|
|
||||||
mplane_t * plane; // pointer to shared plane
|
|
||||||
int flags; // see SURF_ #defines
|
|
||||||
|
|
||||||
int firstedge; // look up in model->surfedges[], negative numbers
|
|
||||||
int numedges; // are backwards edges
|
|
||||||
|
|
||||||
// surface generation data
|
|
||||||
struct surfcache_s * cachespots[4]; //1c This struct and whatnot is never used in the code.
|
|
||||||
|
|
||||||
short texturemins[2]; //2c // smallest s/t position on the surface.
|
|
||||||
short extents[2]; //30 // ?? s/t texture size, 1..256 for all non-sky surfaces
|
|
||||||
|
|
||||||
mtexinfo_t * texinfo; //34
|
|
||||||
|
|
||||||
// lighting info
|
|
||||||
byte styles[4]; // index into d_lightstylevalue[] for animated lights
|
|
||||||
// no one surface can be effected by more than 4
|
|
||||||
// animated lights.
|
|
||||||
color24_t * samples;
|
|
||||||
|
|
||||||
struct decal_s * pdecals;
|
|
||||||
} msurface_t;
|
|
||||||
|
|
||||||
typedef struct dmodel_s { //0x40
|
|
||||||
|
|
||||||
float mins[3], maxs[3];
|
|
||||||
float origin[3]; //18
|
|
||||||
int headnode[4]; //24
|
|
||||||
int visleafs; //34 // not including the solid leaf 0
|
|
||||||
int firstface, numfaces;
|
|
||||||
} dmodel_t;
|
|
||||||
typedef struct model_s {
|
|
||||||
|
|
||||||
char name[64]; //00
|
|
||||||
int loadstate; //40, was bool, is now thought to be enumerated
|
|
||||||
|
|
||||||
int modeltype; //44, the enum modtype_t? That enum will no doubt have changed.
|
|
||||||
// int fromgame; fromgame_t
|
|
||||||
int numframes; //48
|
|
||||||
synctype_t synctype; //dunno what.
|
|
||||||
|
|
||||||
int flags; //50
|
|
||||||
// int engineflags;
|
|
||||||
// int particleeffect;
|
|
||||||
// int particletrail;
|
|
||||||
// int traildefaultindex; //64
|
|
||||||
|
|
||||||
// models:
|
|
||||||
vec3_t mins;//54
|
|
||||||
vec3_t maxs;//60
|
|
||||||
float radius; //6c
|
|
||||||
|
|
||||||
// solid:
|
|
||||||
// qboolean clipbox;
|
|
||||||
// vec3_t clipmins; //88
|
|
||||||
// vec3_t clipmaxs; //94
|
|
||||||
|
|
||||||
// brush:
|
|
||||||
int firstmodelsurface; //70
|
|
||||||
int nummodelsurfaces;
|
|
||||||
|
|
||||||
int numsubmodels;
|
|
||||||
dmodel_t *submodels; //7c, listed as mmodel_t in QW
|
|
||||||
|
|
||||||
int numplanes; //80
|
|
||||||
mplane_t *planes;
|
|
||||||
|
|
||||||
int numleafs;
|
|
||||||
mleaf_t *leafs;
|
|
||||||
|
|
||||||
int numvertexes;
|
|
||||||
mvertex_t *vertexes;
|
|
||||||
|
|
||||||
int numedges;
|
|
||||||
medge_t *edges;
|
|
||||||
|
|
||||||
int numnodes; //a0
|
|
||||||
mnode_t *nodes;
|
|
||||||
|
|
||||||
int numtexinfo;
|
|
||||||
mtexinfo_t *texinfo;
|
|
||||||
|
|
||||||
int numsurfaces;
|
|
||||||
msurface_t *surfaces;
|
|
||||||
|
|
||||||
int numsurfedges;
|
|
||||||
int *surfedges;
|
|
||||||
|
|
||||||
int numclipnodes; //c0
|
|
||||||
dclipnode_t *clipnodes;
|
|
||||||
|
|
||||||
int nummarksurfaces;
|
|
||||||
msurface_t **marksurfaces;
|
|
||||||
|
|
||||||
hull_t hulls[4]; //d0, [16] in QW
|
|
||||||
|
|
||||||
int numtextures; //170
|
|
||||||
texture_t **textures;
|
|
||||||
|
|
||||||
byte * visdata;
|
|
||||||
// void *vis;
|
|
||||||
byte * lightdata;
|
|
||||||
// byte *deluxdata;
|
|
||||||
// struct q3lightgridinfo_t *lightgrid;
|
|
||||||
char * entities; //180
|
|
||||||
|
|
||||||
// void *terrain;
|
|
||||||
|
|
||||||
// unsigned int checksum;
|
|
||||||
// unsigned int checksum2;
|
|
||||||
|
|
||||||
// bspfuncs_t funcs;
|
|
||||||
|
|
||||||
cache_user_t cache; // only access through Mod_Extradata
|
|
||||||
} model_t;
|
|
||||||
|
|
||||||
#define MIPLEVELS 4
|
|
||||||
typedef struct miptex_s { //0x28
|
|
||||||
|
|
||||||
char name[16]; //00
|
|
||||||
unsigned width, height; //10
|
|
||||||
unsigned offsets[MIPLEVELS]; //18 // four mip maps stored
|
|
||||||
} miptex_t;
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_MAP_HULLSDQ1 4
|
|
||||||
typedef struct dq1model_s { //40 structure confirmed.
|
|
||||||
|
|
||||||
float mins[3], maxs[3];
|
|
||||||
float origin[3]; //18
|
|
||||||
int headnode[MAX_MAP_HULLSDQ1]; //24
|
|
||||||
int visleafs; //34 // not including the solid leaf 0
|
|
||||||
int firstface, numfaces; //38
|
|
||||||
} dq1model_t;
|
|
||||||
|
|
||||||
typedef struct TextureStruct1_s {
|
|
||||||
|
|
||||||
short values[4]; //00, I'm thinking it might be an RGBA color struct.
|
|
||||||
} TextureStruct1_t;
|
|
||||||
//This is a THREE BYTE struct. It is used by files--HL later pads it into the struct above.
|
|
||||||
//I do not use it because I don't like packing. I instead treat the data like an array.
|
|
||||||
typedef struct TextureStruct1alt_s {
|
|
||||||
|
|
||||||
char values[3]; //00
|
|
||||||
} TextureStruct1alt_t;
|
|
||||||
typedef struct TextureStruct2_s {
|
|
||||||
|
|
||||||
short NumStructs;
|
|
||||||
TextureStruct1_t structs[];
|
|
||||||
} TextureStruct2_t;
|
|
||||||
|
|
||||||
#define MAXLIGHTMAPS 4
|
|
||||||
typedef struct dface_s {
|
|
||||||
short planenum;
|
|
||||||
short side;
|
|
||||||
|
|
||||||
int firstedge; // we must support > 64k edges
|
|
||||||
short numedges;
|
|
||||||
short texinfo;
|
|
||||||
|
|
||||||
// lighting info
|
|
||||||
byte styles[MAXLIGHTMAPS];
|
|
||||||
int lightofs; // start of [numstyles*surfsize] samples
|
|
||||||
} dface_t;
|
|
||||||
|
|
||||||
#define MAXALIASVERTS 2000
|
|
||||||
#define ALIAS_VERSION 6
|
|
||||||
#define ALIAS_BASE_SIZE_RATIO (1.0 / 11.0)
|
|
||||||
typedef struct dmdl_s { //sizeof(54h)
|
|
||||||
int ident; //00
|
|
||||||
int version; //04 *
|
|
||||||
vec3_t scale; //08
|
|
||||||
vec3_t scale_origin; //14
|
|
||||||
float boundingradius; //20
|
|
||||||
vec3_t eyeposition; //24
|
|
||||||
int numskins; //30
|
|
||||||
int skinwidth; //34
|
|
||||||
int skinheight; //38
|
|
||||||
int numverts; //3c *
|
|
||||||
int numtris; //40 *
|
|
||||||
int numframes; //44 *
|
|
||||||
synctype_t synctype; //48
|
|
||||||
int flags; //4c
|
|
||||||
float size; //50
|
|
||||||
} dmdl_t;
|
|
||||||
typedef struct mmdl_s {
|
|
||||||
int ident;
|
|
||||||
int version;
|
|
||||||
vec3_t scale;
|
|
||||||
vec3_t scale_origin;
|
|
||||||
float boundingradius;
|
|
||||||
vec3_t eyeposition;
|
|
||||||
int numskins;
|
|
||||||
int skinwidth;
|
|
||||||
int skinheight;
|
|
||||||
int numverts;
|
|
||||||
//int numstverts; //Doesn't appear to be in HL.
|
|
||||||
int numtris;
|
|
||||||
int numframes;
|
|
||||||
synctype_t synctype;
|
|
||||||
int flags;
|
|
||||||
float size;
|
|
||||||
} mmdl_t;
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_LBM_HEIGHT 480
|
|
||||||
#define MAX_SKINS 32
|
|
||||||
typedef struct mtriangle_s { //This is NOT what QW uses.
|
|
||||||
int facesfront;
|
|
||||||
int xyz_index[3];
|
|
||||||
//int st_index[3];
|
|
||||||
|
|
||||||
//int pad[2];
|
|
||||||
} mtriangle_t;
|
|
||||||
typedef struct dtriangle_s {
|
|
||||||
int facesfront;
|
|
||||||
int vertindex[3];
|
|
||||||
} dtriangle_t;
|
|
||||||
|
|
||||||
typedef struct dstvert_s {
|
|
||||||
int onseam;
|
|
||||||
int s;
|
|
||||||
int t;
|
|
||||||
} dstvert_t;
|
|
||||||
typedef struct mstvert_s { //same.
|
|
||||||
int onseam;
|
|
||||||
int s;
|
|
||||||
int t;
|
|
||||||
} mstvert_t;
|
|
||||||
|
|
||||||
typedef struct dtrivertx_s {
|
|
||||||
byte v[3];
|
|
||||||
byte lightnormalindex;
|
|
||||||
} dtrivertx_t;
|
|
||||||
|
|
||||||
typedef struct dmd2stvert_s {
|
|
||||||
short s;
|
|
||||||
short t;
|
|
||||||
} dmd2stvert_t;
|
|
||||||
|
|
||||||
typedef struct dmd2triangle_s {
|
|
||||||
short xyz_index[3];
|
|
||||||
short st_index[3];
|
|
||||||
} dmd2triangle_t;
|
|
||||||
|
|
||||||
|
|
||||||
#define DT_FACES_FRONT 0x0010
|
|
||||||
|
|
||||||
typedef struct daliasframe_s { //0x18
|
|
||||||
dtrivertx_t bboxmin; // lightnormal isn't used
|
|
||||||
dtrivertx_t bboxmax; // lightnormal isn't used
|
|
||||||
char name[16]; // frame name from grabbing
|
|
||||||
} daliasframe_t;
|
|
||||||
|
|
||||||
typedef struct daliasinterval_s {
|
|
||||||
float interval;
|
|
||||||
} daliasinterval_t;
|
|
||||||
|
|
||||||
typedef struct daliasskininterval_s {
|
|
||||||
float interval;
|
|
||||||
} daliasskininterval_t;
|
|
||||||
|
|
||||||
typedef struct daliasframetype_s {
|
|
||||||
aliasframetype_t type;
|
|
||||||
} daliasframetype_t;
|
|
||||||
|
|
||||||
typedef struct daliasskintype_s {
|
|
||||||
aliasskintype_t type;
|
|
||||||
} daliasskintype_t;
|
|
||||||
|
|
||||||
typedef struct maliasskindesc_s {
|
|
||||||
aliasskintype_t type;
|
|
||||||
void *pcachespot;
|
|
||||||
int skin;
|
|
||||||
} maliasskindesc_t;
|
|
||||||
|
|
||||||
typedef struct maliasframedesc_s {
|
|
||||||
|
|
||||||
|
|
||||||
aliasframetype_t type;
|
|
||||||
|
|
||||||
int firstpose;
|
|
||||||
int numposes;
|
|
||||||
float interval;
|
|
||||||
dtrivertx_t bboxmin;
|
|
||||||
dtrivertx_t bboxmax;
|
|
||||||
|
|
||||||
vec3_t scale;
|
|
||||||
vec3_t scale_origin;
|
|
||||||
|
|
||||||
int frame;
|
|
||||||
char name[16];
|
|
||||||
} maliasframedesc_t;
|
|
||||||
|
|
||||||
typedef struct aliashdr_s {
|
|
||||||
|
|
||||||
int model;
|
|
||||||
int stverts;
|
|
||||||
int skindesc;
|
|
||||||
int triangles;
|
|
||||||
int something; //colors? Something to do with textures?
|
|
||||||
maliasframedesc_t frames[1];
|
|
||||||
/* //This appears to be very wrong.
|
|
||||||
int ident;
|
|
||||||
int version;
|
|
||||||
vec3_t scale;
|
|
||||||
vec3_t scale_origin;
|
|
||||||
float boundingradius;
|
|
||||||
vec3_t eyeposition;
|
|
||||||
int numskins;
|
|
||||||
int skinwidth;
|
|
||||||
int skinheight;
|
|
||||||
int numverts;
|
|
||||||
int numtris;
|
|
||||||
int numframes;
|
|
||||||
synctype_t synctype;
|
|
||||||
int flags;
|
|
||||||
float size;
|
|
||||||
#ifdef SWQUAKE
|
|
||||||
int model;
|
|
||||||
int stverts;
|
|
||||||
int skindesc;
|
|
||||||
#endif
|
|
||||||
int numposes;
|
|
||||||
int poseverts;
|
|
||||||
int posedata; // numposes*poseverts trivert_t
|
|
||||||
|
|
||||||
int baseposedata; //original verts for triangles to reference
|
|
||||||
int triangles; //we need tri data for shadow volumes
|
|
||||||
|
|
||||||
int commands; // gl command list with embedded s/t
|
|
||||||
int gl_texturenum[MAX_SKINS][4];
|
|
||||||
int texels[MAX_SKINS];
|
|
||||||
maliasframedesc_t frames[]; // variable sized
|
|
||||||
*/
|
|
||||||
} aliashdr_t;
|
|
||||||
|
|
||||||
typedef struct maliasgroupframedesc_s {
|
|
||||||
dtrivertx_t bboxmin;
|
|
||||||
dtrivertx_t bboxmax;
|
|
||||||
int frame;
|
|
||||||
} maliasgroupframedesc_t;
|
|
||||||
|
|
||||||
typedef struct daliasgroup_s { //0x0C
|
|
||||||
int numframes;
|
|
||||||
dtrivertx_t bboxmin; // lightnormal isn't used
|
|
||||||
dtrivertx_t bboxmax; // lightnormal isn't used
|
|
||||||
} daliasgroup_t;
|
|
||||||
typedef struct maliasgroup_s { //0x14
|
|
||||||
|
|
||||||
int numframes;
|
|
||||||
int intervals;
|
|
||||||
maliasgroupframedesc_t frames[1];
|
|
||||||
} maliasgroup_t;
|
|
||||||
|
|
||||||
typedef struct daliasskingroup_s { //0x04
|
|
||||||
int numskins;
|
|
||||||
} daliasskingroup_t;
|
|
||||||
typedef struct maliasskingroup_s {
|
|
||||||
int numskins;
|
|
||||||
int intervals;
|
|
||||||
maliasskindesc_t skindescs[1];
|
|
||||||
} maliasskingroup_t;
|
|
||||||
|
|
||||||
#define SPRITEHL_VERSION 2
|
|
||||||
|
|
||||||
typedef struct mspriteframe_s { //0x20
|
|
||||||
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
float up, down, left, right;
|
|
||||||
int gl_texturenum;
|
|
||||||
byte pixels[4];
|
|
||||||
|
|
||||||
} mspriteframe_t;
|
|
||||||
typedef struct dspriteframe_s { //0x10
|
|
||||||
|
|
||||||
int origin[2]; //00
|
|
||||||
int width; //08
|
|
||||||
int height; //0c
|
|
||||||
} dspriteframe_t;
|
|
||||||
|
|
||||||
typedef struct dspriteinterval_s {
|
|
||||||
float interval;
|
|
||||||
} dspriteinterval_t;
|
|
||||||
|
|
||||||
typedef struct dspriteframetype_s {
|
|
||||||
spriteframetype_t type;
|
|
||||||
} dspriteframetype_t;
|
|
||||||
|
|
||||||
typedef struct mspriteframedesc_s {
|
|
||||||
|
|
||||||
spriteframetype_t type;
|
|
||||||
mspriteframe_t *frameptr;
|
|
||||||
} mspriteframedesc_t;
|
|
||||||
|
|
||||||
typedef struct dsprite_s { //0x28
|
|
||||||
|
|
||||||
int ident;
|
|
||||||
int version;
|
|
||||||
int type;
|
|
||||||
int padding0c; //size value
|
|
||||||
float boundingradius;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int numframes;
|
|
||||||
float beamlength;
|
|
||||||
synctype_t synctype;
|
|
||||||
} dsprite_t;
|
|
||||||
typedef struct msprite_s { //Inaccurate.
|
|
||||||
|
|
||||||
short type;
|
|
||||||
short padding02;
|
|
||||||
int maxwidth;
|
|
||||||
int maxheight;
|
|
||||||
int numframes;
|
|
||||||
int padding10;
|
|
||||||
float beamlength;
|
|
||||||
int padding18;
|
|
||||||
mspriteframedesc_t frames[1];
|
|
||||||
/*
|
|
||||||
int type;
|
|
||||||
int maxwidth;
|
|
||||||
int maxheight;
|
|
||||||
int numframes;
|
|
||||||
int padding10;
|
|
||||||
int padding14;
|
|
||||||
float beamlength;
|
|
||||||
mspriteframedesc_t frames[1]; //1C
|
|
||||||
*/
|
|
||||||
} msprite_t;
|
|
||||||
|
|
||||||
typedef struct dspritegroup_s {
|
|
||||||
int numframes;
|
|
||||||
} dspritegroup_t;
|
|
||||||
typedef struct mspritegroup_s { //0x0C
|
|
||||||
|
|
||||||
int numframes;
|
|
||||||
float * intervals;
|
|
||||||
mspriteframe_t *frames[1];
|
|
||||||
} mspritegroup_t;
|
|
||||||
|
|
||||||
typedef struct mstudiobodyparts_s { //0x4C
|
|
||||||
|
|
||||||
char name[64]; //00
|
|
||||||
int nummodels; //40
|
|
||||||
int base; //44
|
|
||||||
int modelindex; //48 index into models array
|
|
||||||
} mstudiobodyparts_t;
|
|
||||||
typedef struct mstudiotexture_s {
|
|
||||||
|
|
||||||
char name[64]; //00
|
|
||||||
int flags; //40
|
|
||||||
int width; //44
|
|
||||||
int height; //48
|
|
||||||
int index; //4c
|
|
||||||
} mstudiotexture_t;
|
|
||||||
|
|
||||||
typedef struct mstudiomodel_s { //0x70
|
|
||||||
|
|
||||||
char name[64]; //00
|
|
||||||
|
|
||||||
int type; //40
|
|
||||||
|
|
||||||
float boundingradius; //44
|
|
||||||
|
|
||||||
int nummesh; //48
|
|
||||||
int meshindex; //4C
|
|
||||||
|
|
||||||
int numverts; // 50 number of unique vertices
|
|
||||||
int vertinfoindex; // 54 vertex bone info
|
|
||||||
int vertindex; // 58 vertex vec3_t
|
|
||||||
int numnorms; // 5c number of unique surface normals
|
|
||||||
int norminfoindex; // 60 normal bone info
|
|
||||||
int normindex; // 64 normal vec3_t
|
|
||||||
|
|
||||||
int numgroups; // 68 deformation groups
|
|
||||||
int groupindex; // 6c
|
|
||||||
} mstudiomodel_t;
|
|
||||||
|
|
||||||
//functions
|
|
||||||
void Mod_Init();
|
|
||||||
void Mod_ClearAll();
|
|
||||||
void Mod_Shutdown();
|
|
||||||
|
|
||||||
model_t * Mod_ForName(char *, int, int);
|
|
||||||
mleaf_t * Mod_PointInLeaf(vec3_t, model_t *);
|
|
||||||
byte *Mod_LeafPVS(mleaf_t *, model_t *);
|
|
||||||
HLDS_DLLEXPORT void * Mod_Extradata(model_t *);
|
|
||||||
int CM_HeadnodeVisible(mnode_t *, byte *, int *);
|
|
||||||
|
|
||||||
byte * CM_LeafPAS(int);
|
|
||||||
byte * CM_LeafPVS(int);
|
|
||||||
void CM_CalcPAS(model_t *);
|
|
||||||
void CM_FreePAS();
|
|
||||||
|
|
||||||
//sdk
|
|
||||||
HLDS_DLLEXPORT int ModelFrames(int);
|
|
||||||
#endif
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/* This file, in an effort to try piecing together the calling conventions
|
|
||||||
// used by mods, defines two vars. That's it.
|
|
||||||
//
|
|
||||||
// It's in this file instead of Modding because Modding.h includes a lot
|
|
||||||
// of other headers. And we don't want to risk roundabout dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_CALLING_CONVENTIONS_HEADER
|
|
||||||
#define OSHLDS_CALLING_CONVENTIONS_HEADER
|
|
||||||
|
|
||||||
// *Current notes: structure alignment (how much padding they get to reach a
|
|
||||||
// boundary) is 8. GCC says it uses 8 by default; VS has more control over
|
|
||||||
// that, but lists 8 as default and it's the default for mods themselves)
|
|
||||||
// *The difference between a working MSVC6 DLL and a nonworking one is the
|
|
||||||
// optimization "Frame Pointer Omission". Nobody seems to know why.
|
|
||||||
// *Traces through the few working functions indicate EBX ESI EDI are correctly
|
|
||||||
// popped. Subtle corruptions seems unlikely.
|
|
||||||
|
|
||||||
//Even if these end up being useless, it's still an easy way to ID mod functions.
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define HLDS_DLLEXPORT __declspec(dllexport)
|
|
||||||
#define HLDS_DLLIMPORT __declspec(dllimport)
|
|
||||||
#else
|
|
||||||
#define HLDS_DLLEXPORT
|
|
||||||
#define HLDS_DLLIMPORT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,339 +0,0 @@
|
|||||||
/* I'd like to put all code that is related to setting up mods here.
|
|
||||||
// This'd include the remaining functions in HIJACK.c, as well as what's
|
|
||||||
// here now, testing to ensure the structures match.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_MODDING_HEADER
|
|
||||||
#define OSHLDS_MODDING_HEADER
|
|
||||||
|
|
||||||
/* Calling conventions: Still haven't figured them out. There's a line,
|
|
||||||
// #define DLLEXPORT __stdcall in the SDK, but the disassembly of hl.dll
|
|
||||||
// disagrees. It's also possible that its our calling that's wrong
|
|
||||||
// somewhere.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "crc.h"
|
|
||||||
#include "common.h"
|
|
||||||
#include "cvar.h"
|
|
||||||
#include "edict.h"
|
|
||||||
#include "Mod.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "report.h"
|
|
||||||
#include "SV_hlds.h"
|
|
||||||
#include "world.h"
|
|
||||||
|
|
||||||
//Types related to unfinished SDK functions (most likely knowm by other names)
|
|
||||||
typedef void SAVERESTOREDATA; //It's a large struct but I don't feel like digging it out
|
|
||||||
typedef void KeyValueData;
|
|
||||||
typedef void TYPEDESCRIPTION;
|
|
||||||
|
|
||||||
typedef struct enginefuncs_s { //sdk, duh. MODS call these from US.
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT int (*pfnPrecacheModel) (char* s);
|
|
||||||
HLDS_DLLEXPORT int (*pfnPrecacheSound) (char* s);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetModel) (edict_t *e, const char *m);
|
|
||||||
HLDS_DLLEXPORT int (*pfnModelIndex) (char *m);
|
|
||||||
HLDS_DLLEXPORT int (*pfnModelFrames) (int modelIndex);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetSize) (edict_t *e, const vec3_t rgflMin, const vec3_t rgflMax);
|
|
||||||
HLDS_DLLEXPORT void (*pfnChangeLevel) (char* s1, char* s2);
|
|
||||||
HLDS_DLLEXPORT void (*pfnGetSpawnParms) (edict_t *ent);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSaveSpawnParms) (edict_t *ent);
|
|
||||||
HLDS_DLLEXPORT float (*pfnVecToYaw) (const float *rgflVector);
|
|
||||||
HLDS_DLLEXPORT void (*pfnVecToAngles) (const float *rgflVectorIn, float *rgflVectorOut);
|
|
||||||
HLDS_DLLEXPORT void (*pfnMoveToOrigin) (edict_t *ent,const vec3_t pflGoal, float dist, int iMoveType);
|
|
||||||
HLDS_DLLEXPORT void (*pfnChangeYaw) (edict_t* ent);
|
|
||||||
HLDS_DLLEXPORT void (*pfnChangePitch) (edict_t* ent);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnFindEntityByString) (edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue);
|
|
||||||
HLDS_DLLEXPORT int (*pfnGetEntityIllum) (edict_t* pEnt);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnFindEntityInSphere) (edict_t *pEdictStartSearchAfter, const vec3_t org, float rad);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnFindClientInPVS) (edict_t *pEdict);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnEntitiesInPVS) (edict_t *pplayer);
|
|
||||||
HLDS_DLLEXPORT void (*pfnMakeVectors) (const vec3_t rgflVector);
|
|
||||||
HLDS_DLLEXPORT void (*pfnAngleVectors) (const vec3_t rgflVector, float *forward, float *right, float *up);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnCreateEntity) (void);
|
|
||||||
HLDS_DLLEXPORT void (*pfnRemoveEntity) (edict_t* e);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnCreateNamedEntity) (int className);
|
|
||||||
HLDS_DLLEXPORT void (*pfnMakeStatic) (edict_t *ent);
|
|
||||||
HLDS_DLLEXPORT int (*pfnEntIsOnFloor) (edict_t *e);
|
|
||||||
HLDS_DLLEXPORT int (*pfnDropToFloor) (edict_t* e);
|
|
||||||
HLDS_DLLEXPORT int (*pfnWalkMove) (edict_t *ent, float yaw, float dist, int iMode);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetOrigin) (edict_t *e, const vec3_t rgflOrigin);
|
|
||||||
HLDS_DLLEXPORT void (*pfnEmitSound) (edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch);
|
|
||||||
HLDS_DLLEXPORT void (*pfnEmitAmbientSound) (edict_t *entity, vec3_t pos, const char *samp, float vol, float attenuation, int fFlags, int pitch);
|
|
||||||
HLDS_DLLEXPORT void (*pfnTraceLine) (vec3_t v1, vec3_t v2, int fNoMonsters, edict_t *pentToSkip, TraceResult_t *ptr);
|
|
||||||
HLDS_DLLEXPORT void (*pfnTraceToss) (edict_t* pent, edict_t* pentToIgnore, TraceResult_t *ptr);
|
|
||||||
HLDS_DLLEXPORT int (*pfnTraceMonsterHull) (edict_t *pEdict, vec3_t v1, vec3_t v2, int fNoMonsters, edict_t *pentToSkip, TraceResult_t *ptr);
|
|
||||||
HLDS_DLLEXPORT void (*pfnTraceHull) (vec3_t v1, vec3_t v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult_t *ptr);
|
|
||||||
HLDS_DLLEXPORT void (*pfnTraceModel) (vec3_t v1, vec3_t v2, int hullNumber, edict_t *pent, TraceResult_t *ptr);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnTraceTexture) (edict_t *pTextureEntity, vec3_t v1, vec3_t v2 );
|
|
||||||
HLDS_DLLEXPORT void (*pfnTraceSphere) (vec3_t v1, vec3_t v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult_t *ptr);
|
|
||||||
HLDS_DLLEXPORT void (*pfnGetAimVector) (edict_t* ent, float speed, vec3_t rgflReturn);
|
|
||||||
HLDS_DLLEXPORT void (*pfnServerCommand) (char* str);
|
|
||||||
HLDS_DLLEXPORT void (*pfnServerExecute) (void);
|
|
||||||
HLDS_DLLEXPORT void (*pfnClientCommand) (edict_t* pEdict, char* szFmt, ...);
|
|
||||||
HLDS_DLLEXPORT void (*pfnParticleEffect) (const vec3_t org, const vec3_t dir, float color, float count);
|
|
||||||
HLDS_DLLEXPORT void (*pfnLightStyle) (int style, char* val);
|
|
||||||
HLDS_DLLEXPORT int (*pfnDecalIndex) (const char *name);
|
|
||||||
HLDS_DLLEXPORT int (*pfnPointContents) (const vec3_t rgflVector);
|
|
||||||
HLDS_DLLEXPORT void (*pfnMessageBegin) (int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
|
|
||||||
HLDS_DLLEXPORT void (*pfnMessageEnd) (void);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteByte) (int iValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteChar) (int iValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteShort) (int iValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteLong) (int iValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteAngle) (float flValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteCoord) (float flValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteString) (const char *sz);
|
|
||||||
HLDS_DLLEXPORT void (*pfnWriteEntity) (int iValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCVarRegister) (cvar_t *pCvar);
|
|
||||||
HLDS_DLLEXPORT float (*pfnCVarGetFloat) (const char *szVarName);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnCVarGetString) (const char *szVarName);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCVarSetFloat) (const char *szVarName, float flValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCVarSetString) (const char *szVarName, const char *szValue);
|
|
||||||
HLDS_DLLEXPORT void (*pfnAlertMessage) (ALERT_TYPE atype, char *szFmt, ...);
|
|
||||||
HLDS_DLLEXPORT void (*pfnEngineFprintf) (FILE *pfile, char *szFmt, ...);
|
|
||||||
HLDS_DLLEXPORT void * (*pfnPvAllocEntPrivateData) (edict_t *pEdict, long cb);
|
|
||||||
HLDS_DLLEXPORT void * (*pfnPvEntPrivateData) (edict_t *pEdict);
|
|
||||||
HLDS_DLLEXPORT void (*pfnFreeEntPrivateData) (edict_t *pEdict);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnSzFromIndex) (int iString);
|
|
||||||
HLDS_DLLEXPORT int (*pfnAllocString) (const char *szValue);
|
|
||||||
HLDS_DLLEXPORT entvars_t * (*pfnGetVarsOfEnt) (edict_t *pEdict);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnPEntityOfEntOffset) (int iEntOffset);
|
|
||||||
HLDS_DLLEXPORT int (*pfnEntOffsetOfPEntity) (const edict_t *pEdict);
|
|
||||||
HLDS_DLLEXPORT int (*pfnIndexOfEdict) (const edict_t *pEdict);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnPEntityOfEntIndex) (int iEntIndex);
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnFindEntityByVars) (struct entvars_s* pvars);
|
|
||||||
HLDS_DLLEXPORT void * (*pfnGetModelPtr) (edict_t* pEdict);
|
|
||||||
HLDS_DLLEXPORT int (*pfnRegUserMsg) (const char *pszName, int iSize);
|
|
||||||
HLDS_DLLEXPORT void (*pfnAnimationAutomove) (const edict_t* pEdict, float flTime);
|
|
||||||
HLDS_DLLEXPORT void (*pfnGetBonePosition) (const edict_t* pEdict, int iBone, float *rgflOrigin, float *rgflAngles);
|
|
||||||
HLDS_DLLEXPORT void * (*pfnFunctionFromName) (const char *pName);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnNameForFunction) (void * function);
|
|
||||||
HLDS_DLLEXPORT void (*pfnClientPrintf) (edict_t* pEdict, PRINT_TYPE ptype, const char *szMsg); // JOHN: engine callbacks so game DLL can print messages to individual clients
|
|
||||||
HLDS_DLLEXPORT void (*pfnServerPrint) (const char *szMsg);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnCmd_Args) (void); // these 3 added
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnCmd_Argv) (int argc); // so game DLL can easily
|
|
||||||
HLDS_DLLEXPORT int (*pfnCmd_Argc) (void); // access client 'cmd' strings
|
|
||||||
HLDS_DLLEXPORT void (*pfnGetAttachment) (const edict_t *pEdict, int iAttachment, vec3_t rgflOrigin, vec3_t rgflAngles );
|
|
||||||
HLDS_DLLEXPORT void (*pfnCRC32_Init) (CRC32_t *pulCRC);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCRC32_ProcessBuffer) (CRC32_t *pulCRC, void *p, int len);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCRC32_ProcessByte) (CRC32_t *pulCRC, unsigned char ch);
|
|
||||||
HLDS_DLLEXPORT CRC32_t (*pfnCRC32_Final) (CRC32_t pulCRC);
|
|
||||||
HLDS_DLLEXPORT long (*pfnRandomLong) (long lLow, long lHigh);
|
|
||||||
HLDS_DLLEXPORT float (*pfnRandomFloat) (float flLow, float flHigh);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetView) (const edict_t *pClient, const edict_t *pViewent);
|
|
||||||
HLDS_DLLEXPORT float (*pfnTime) (void);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCrosshairAngle) (const edict_t *pClient, float pitch, float yaw);
|
|
||||||
HLDS_DLLEXPORT byte * (*pfnLoadFileForMe) (const char *filename, int *pLength);
|
|
||||||
HLDS_DLLEXPORT void (*pfnFreeFile) (byte *buffer);
|
|
||||||
HLDS_DLLEXPORT void (*pfnEndSection) (const char *pszSectionName); // trigger_endsection
|
|
||||||
HLDS_DLLEXPORT int (*pfnCompareFileTime) (char *filename1, char *filename2, int *iCompare);
|
|
||||||
HLDS_DLLEXPORT void (*pfnGetGameDir) (char *szGetGameDir);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCvar_RegisterVariable) (cvar_t *variable);
|
|
||||||
HLDS_DLLEXPORT void (*pfnFadeClientVolume) (const edict_t *pEdict, int fadePercent, int fadeOutSeconds, int holdTime, int fadeInSeconds);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetClientMaxspeed) (edict_t *pEdict, float fNewMaxspeed); //It lies. We are changing the entvars, which is part of the edict, and therefore the edict is not constant.
|
|
||||||
HLDS_DLLEXPORT edict_t * (*pfnCreateFakeClient) (const char *netname); // returns NULL if fake client can't be created
|
|
||||||
HLDS_DLLEXPORT void (*pfnRunPlayerMove) (edict_t * fakeclient, const vec3_t viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec);
|
|
||||||
HLDS_DLLEXPORT int (*pfnNumberOfEntities) (void);
|
|
||||||
HLDS_DLLEXPORT char * (*pfnGetInfoKeyBuffer) (edict_t *e); // passing in NULL gets the serverinfo
|
|
||||||
HLDS_DLLEXPORT char * (*pfnInfoKeyValue) (char *infobuffer, char *key);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetKeyValue) (char *infobuffer, char *key, char *value);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetClientKeyValue) (int clientIndex, char *infobuffer, char *key, char *value);
|
|
||||||
HLDS_DLLEXPORT int (*pfnIsMapValid) (char *filename);
|
|
||||||
HLDS_DLLEXPORT void (*pfnStaticDecal) (const float *origin, int decalIndex, int entityIndex, int modelIndex);
|
|
||||||
HLDS_DLLEXPORT int (*pfnPrecacheGeneric) (char* s);
|
|
||||||
HLDS_DLLEXPORT int (*pfnGetPlayerUserId) (edict_t *e); // returns the server assigned userid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
|
|
||||||
HLDS_DLLEXPORT void (*pfnBuildSoundMsg) (edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const vec3_t pOrigin, edict_t *ed);
|
|
||||||
HLDS_DLLEXPORT int (*pfnIsDedicatedServer) (void);// is this a dedicated server?
|
|
||||||
HLDS_DLLEXPORT cvar_t * (*pfnCVarGetPointer) (const char *szVarName);
|
|
||||||
HLDS_DLLEXPORT unsigned int (*pfnGetPlayerWONId) (edict_t *e); // returns the server assigned WONid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
|
|
||||||
|
|
||||||
// YWB 8/1/99 TFF Physics additions
|
|
||||||
HLDS_DLLEXPORT void (*pfnInfo_RemoveKey) (char *s, const char *key);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnGetPhysicsKeyValue) (const edict_t *pClient, const char *key);
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetPhysicsKeyValue) (const edict_t *pClient, const char *key, const char *value);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnGetPhysicsInfoString) (const edict_t *pClient);
|
|
||||||
HLDS_DLLEXPORT unsigned short (*pfnPrecacheEvent) (int type, const char*psz);
|
|
||||||
HLDS_DLLEXPORT void (*pfnPlaybackEvent) (int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT unsigned char * (*pfnSetFatPVS) (vec3_t org);
|
|
||||||
HLDS_DLLEXPORT unsigned char * (*pfnSetFatPAS) (vec3_t org);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT int (*pfnCheckVisibility ) (const edict_t *entity, unsigned char *pset);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void (*pfnDeltaSetField) (struct sv_builddelta_s *pFields, const char *fieldname);
|
|
||||||
HLDS_DLLEXPORT void (*pfnDeltaUnsetField) (struct sv_builddelta_s *pFields, const char *fieldname);
|
|
||||||
HLDS_DLLEXPORT void (*pfnDeltaAddEncoder) (char *name, void (*conditionalencode)(struct sv_builddelta_s *pFields, const unsigned char *from, const unsigned char *to));
|
|
||||||
HLDS_DLLEXPORT int (*pfnGetCurrentPlayer) (void);
|
|
||||||
HLDS_DLLEXPORT int (*pfnCanSkipPlayer) (const edict_t *player);
|
|
||||||
HLDS_DLLEXPORT int (*pfnDeltaFindField) (struct sv_builddelta_s *pFields, const char *fieldname);
|
|
||||||
HLDS_DLLEXPORT void (*pfnDeltaSetFieldByIndex) (struct sv_builddelta_s *pFields, int fieldNumber);
|
|
||||||
HLDS_DLLEXPORT void (*pfnDeltaUnsetFieldByIndex) (struct sv_builddelta_s *pFields, int fieldNumber);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void (*pfnSetGroupMask) (int mask, int op);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT int (*pfnCreateInstancedBaseline) (int classname, entity_state_t *baseline);
|
|
||||||
HLDS_DLLEXPORT void (*pfnCvar_DirectSet) (struct cvar_s *var, char *value);
|
|
||||||
|
|
||||||
// Forces the client and server to be running with the same version of the specified file
|
|
||||||
// ( e.g., a player model ).
|
|
||||||
// Calling this has no effect in single player
|
|
||||||
HLDS_DLLEXPORT void (*pfnForceUnmodified) (FORCE_TYPE type, vec3_t mins, vec3_t maxs, const char *filename);
|
|
||||||
HLDS_DLLEXPORT void (*pfnGetPlayerStats) (const edict_t *pClient, int *ping, int *packet_loss);
|
|
||||||
HLDS_DLLEXPORT void (*pfnAddServerCommand) (char *cmd_name, void (*function) (void));
|
|
||||||
|
|
||||||
// For voice communications, set which clients hear eachother.
|
|
||||||
// NOTE: these functions take player entity indices (starting at 1).
|
|
||||||
HLDS_DLLEXPORT qboolean (*pfnVoice_GetClientListening) (int iReceiver, int iSender);
|
|
||||||
HLDS_DLLEXPORT qboolean (*pfnVoice_SetClientListening) (int iReceiver, int iSender, qboolean bListen);
|
|
||||||
HLDS_DLLEXPORT const char * (*pfnGetPlayerAuthId) (edict_t *e);
|
|
||||||
|
|
||||||
//No functions below this line are assigned values in the HLDS version 1110.
|
|
||||||
} enginefuncs_t;
|
|
||||||
typedef struct NEW_DLL_FUNCTIONS_s{ //Three functions.
|
|
||||||
// Called right before the object's memory is freed.
|
|
||||||
// Calls its destructor.
|
|
||||||
HLDS_DLLEXPORT void (*pfnOnFreeEntPrivateData)(edict_t *pEnt);
|
|
||||||
HLDS_DLLEXPORT void (*pfnGameShutdown)(void);
|
|
||||||
HLDS_DLLEXPORT int (*pfnShouldCollide)( edict_t *pentTouched, edict_t *pentOther );
|
|
||||||
} NEW_DLL_FUNCTIONS_t;
|
|
||||||
typedef struct Mod_DLL_Functions_s { //50 functions, 200 bytes. WE call these from MODS.
|
|
||||||
|
|
||||||
HLDS_DLLIMPORT void (*pfnGameInit) (void);
|
|
||||||
HLDS_DLLIMPORT int (*pfnSpawn) (edict_t *pent);
|
|
||||||
HLDS_DLLIMPORT void (*pfnThink) (edict_t *pent);
|
|
||||||
HLDS_DLLIMPORT void (*pfnUse) (edict_t *pentUsed, edict_t *pentOther);
|
|
||||||
HLDS_DLLIMPORT void (*pfnTouch) (edict_t *pentTouched, edict_t *pentOther);
|
|
||||||
HLDS_DLLIMPORT void (*pfnBlocked) (edict_t *pentBlocked, edict_t *pentOther);
|
|
||||||
HLDS_DLLIMPORT void (*pfnKeyValue) (edict_t *pentKeyvalue, KeyValueData *pkvd);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSave) (edict_t *pent, SAVERESTOREDATA *pSaveData);
|
|
||||||
HLDS_DLLIMPORT int (*pfnRestore) (edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSetAbsBox) (edict_t *pent);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSaveWriteFields) (SAVERESTOREDATA *, const char *, void *, TYPEDESCRIPTION *, int);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSaveReadFields) (SAVERESTOREDATA *, const char *, void *, TYPEDESCRIPTION *, int);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSaveGlobalState) (SAVERESTOREDATA *);
|
|
||||||
HLDS_DLLIMPORT void (*pfnRestoreGlobalState) (SAVERESTOREDATA *);
|
|
||||||
HLDS_DLLIMPORT void (*pfnResetGlobalState) (void);
|
|
||||||
HLDS_DLLIMPORT qboolean (*pfnClientConnect) (edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]);
|
|
||||||
HLDS_DLLIMPORT void (*pfnClientDisconnect) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnClientKill) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnClientPutInServer) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnClientCommand) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnClientUserInfoChanged) (edict_t *pEntity, char *infobuffer);
|
|
||||||
HLDS_DLLIMPORT void (*pfnServerActivate) (edict_t *pEdictList, int edictCount, int clientMax);
|
|
||||||
HLDS_DLLIMPORT void (*pfnServerDeactivate) (void);
|
|
||||||
HLDS_DLLIMPORT void (*pfnPlayerPreThink) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnPlayerPostThink) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnStartFrame) (void);
|
|
||||||
HLDS_DLLIMPORT void (*pfnParmsNewLevel) (void);
|
|
||||||
HLDS_DLLIMPORT void (*pfnParmsChangeLevel) (void);
|
|
||||||
HLDS_DLLIMPORT const char * (*pfnGetGameDescription) (void);
|
|
||||||
HLDS_DLLIMPORT void (*pfnPlayerCustomization) (edict_t *pEntity, customization_t *pCustom);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSpectatorConnect) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSpectatorDisconnect) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSpectatorThink) (edict_t *pEntity);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSys_Error) (const char *error_string);
|
|
||||||
HLDS_DLLIMPORT void (*pfnPM_Move) (playermove_t *ppmove, qboolean server);
|
|
||||||
HLDS_DLLIMPORT void (*pfnPM_Init) (playermove_t *ppmove);
|
|
||||||
HLDS_DLLIMPORT char (*pfnPM_FindTextureType) (char *name);
|
|
||||||
HLDS_DLLIMPORT void (*pfnSetupVisibility) (edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas);
|
|
||||||
HLDS_DLLIMPORT void (*pfnUpdateClientData) (const edict_t *ent, int sendweapons, clientdata_t *cd);
|
|
||||||
HLDS_DLLIMPORT int (*pfnAddToFullPack) (entity_state_t *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet);
|
|
||||||
HLDS_DLLIMPORT void (*pfnCreateBaseline) (int player, int eindex, entity_state_t *baseline, edict_t *entity, int playermodelindex, const vec3_t player_mins, const vec3_t player_maxs);
|
|
||||||
HLDS_DLLIMPORT void (*pfnRegisterEncoders) (void );
|
|
||||||
HLDS_DLLIMPORT int (*pfnGetWeaponData) (edict_t *player, weapon_data_t *info);
|
|
||||||
HLDS_DLLIMPORT void (*pfnCmdStart) (const edict_t *player, const usercmd_t *cmd, unsigned int random_seed);
|
|
||||||
HLDS_DLLIMPORT void (*pfnCmdEnd) (const edict_t *player);
|
|
||||||
HLDS_DLLIMPORT int (*pfnConnectionlessPacket) (const netadr_t *global_net_from, const char *args, char *response_buffer, int *response_buffer_size);
|
|
||||||
HLDS_DLLIMPORT int (*pfnGetHullBounds) (int hullnumber, const vec3_t mins, const vec3_t maxs);
|
|
||||||
HLDS_DLLIMPORT void (*pfnCreateInstancedBaselines) (void);
|
|
||||||
HLDS_DLLIMPORT int (*pfnInconsistentFile) (const edict_t *player, const char *filename, char *disconnect_message);
|
|
||||||
HLDS_DLLIMPORT int (*pfnAllowLagCompensation) (void);
|
|
||||||
} Mod_DLL_Functions_t;
|
|
||||||
typedef struct SecurityModule_s { //unknown everything. Might as well remove.
|
|
||||||
|
|
||||||
void (*Function1) (void);
|
|
||||||
void (*Function2) (void);
|
|
||||||
void (*Function3) (void);
|
|
||||||
void (*Function4) (void);
|
|
||||||
void (*Function5) (void);
|
|
||||||
void (*Function6) (void);
|
|
||||||
void (*Function7) (netchan_t *, sizebuf_t *);
|
|
||||||
int (*Function8) (netchan_t *, sizebuf_t *); //1c
|
|
||||||
void (*Function9) (void);
|
|
||||||
void (*Function10) (model_t *, byte *);
|
|
||||||
void (*Function11) (void);
|
|
||||||
void (*Function12) (void);
|
|
||||||
void (*Function13) (void);
|
|
||||||
void (*Function14) (void);
|
|
||||||
void (*Function15) (void);
|
|
||||||
void (*Function16) (void);
|
|
||||||
void (*Function17) (void);
|
|
||||||
void (*Function18) (int); //44
|
|
||||||
void (*Function19) (void);
|
|
||||||
void (*Function20) (byte *, int); //4c
|
|
||||||
void (*Function21) (void);
|
|
||||||
void (*Function22) (void);
|
|
||||||
void (*Function23) (void);
|
|
||||||
void (*Function24) (void);
|
|
||||||
void (*Function25) (void);
|
|
||||||
void (*Function26) (void);
|
|
||||||
void (*Function27) (void);
|
|
||||||
void (*Function28) (void);
|
|
||||||
void (*Function29) (void);
|
|
||||||
} SecurityModule_t;
|
|
||||||
|
|
||||||
typedef struct g_vars_s {
|
|
||||||
|
|
||||||
float time;
|
|
||||||
float frametime;
|
|
||||||
float force_retouch;
|
|
||||||
string_t mapname;
|
|
||||||
string_t startspot; //10
|
|
||||||
float deathmatch;
|
|
||||||
float coop;
|
|
||||||
float teamplay;
|
|
||||||
float serverflags;//20
|
|
||||||
float found_secrets;
|
|
||||||
vec3_t v_forward;//28
|
|
||||||
vec3_t v_up;//34
|
|
||||||
vec3_t v_right;//40
|
|
||||||
float trace_allsolid;//4c Why are these floats anyway? Shouldn't they be bools?
|
|
||||||
float trace_startsolid;
|
|
||||||
float trace_fraction;
|
|
||||||
vec3_t trace_endpos;//58
|
|
||||||
vec3_t trace_plane_normal;//64
|
|
||||||
float trace_plane_dist;//70
|
|
||||||
edict_t * trace_ent;
|
|
||||||
float trace_inopen; //78
|
|
||||||
float trace_inwater;
|
|
||||||
int trace_hitgroup; //80
|
|
||||||
int trace_flags;
|
|
||||||
int msg_entity;
|
|
||||||
int cdAudioTrack; //8C Not really verifiable.
|
|
||||||
int maxClients;
|
|
||||||
int maxEntities;
|
|
||||||
char * pStringBase;
|
|
||||||
void * pSaveData; //9C
|
|
||||||
vec3_t vecLandmarkOffset;
|
|
||||||
|
|
||||||
} g_vars_t;
|
|
||||||
|
|
||||||
|
|
||||||
//Large tables of vars. Gotta go somewhere.
|
|
||||||
extern Mod_DLL_Functions_t gEntityInterface;
|
|
||||||
extern g_vars_t gGlobalVariables;
|
|
||||||
extern NEW_DLL_FUNCTIONS_t gNewDLLFunctions;
|
|
||||||
extern SecurityModule_t g_modfuncs;
|
|
||||||
|
|
||||||
|
|
||||||
void * GetDispatch(const char *);
|
|
||||||
void LoadThisDll(const char *);
|
|
||||||
void LoadEntityDLLs();
|
|
||||||
void ReleaseEntityDlls();
|
|
||||||
|
|
||||||
int TestStructureAlignment();
|
|
||||||
void SV_CheckBlendingInterface();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,843 +0,0 @@
|
|||||||
/* The SV_ functions are pretty much a good chunk of code, divided into
|
|
||||||
// separate segments that can't be easily distinguished by name. They use many
|
|
||||||
// global variables and will often build onto each other in a very heirarchial
|
|
||||||
// manner. Most of them handle structs which, unfortunately, are very very
|
|
||||||
// different from what's in QW. Piecing together the structs alone has taken
|
|
||||||
// a lot of the time.
|
|
||||||
//
|
|
||||||
// This file contains portions of code directly related to the sending and
|
|
||||||
// receiving of packets (NET_) as well as the code one level above that which
|
|
||||||
// handles the individual frames.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_NETCHAN_HEADER
|
|
||||||
#define OSHLDS_NETCHAN_HEADER
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "common.h"
|
|
||||||
#include "Mod.h"
|
|
||||||
#include "edict.h"
|
|
||||||
#include "crc.h"
|
|
||||||
#include "secmod.h"
|
|
||||||
|
|
||||||
//The networking includes
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
|
|
||||||
#undef IPPROTO_IPV6 //the netadr_t struct is used by mods. We can't change it.
|
|
||||||
#define SOCKETCLOSE closesocket
|
|
||||||
|
|
||||||
typedef int socklen_t;
|
|
||||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
|
||||||
#define ECONNRESET WSAECONNRESET
|
|
||||||
#define ECONNREFUSED WSAECONNREFUSED
|
|
||||||
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
|
||||||
#define ENETRESET WSAENETRESET
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <sys/unistd.h>
|
|
||||||
#include <sys/fcntl.h>
|
|
||||||
|
|
||||||
#define SOCKET int
|
|
||||||
#define SOCKETCLOSE close
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef SOCKET_ERROR
|
|
||||||
#define SOCKET_ERROR -1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef INVALID_SOCKET
|
|
||||||
#define INVALID_SOCKET -1 //IIRC for Unix this is 0, for Windows it's -1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_MODELS 0x200
|
|
||||||
#define MAX_SOUNDS 0x200
|
|
||||||
#define MAX_GNERIC 0x200
|
|
||||||
#define MAX_LOOPBACK 4
|
|
||||||
|
|
||||||
#define MAX_UDP_ROUTABLE_SIZE 1400 //That damn split packet is nu'un but trouble.
|
|
||||||
#define SIZEOF_splitpacket_header_t 9
|
|
||||||
#define SPLIT_UDP_PACKET_SIZE 1391 //(MAX_UDP_ROUTABLE_SIZE - sizeof(splitpacket_header_t))
|
|
||||||
|
|
||||||
#define MAX_UDP_PACKET_DATA_SIZE 8346 //Steam adds an extra zero to this or so. Overkill.
|
|
||||||
#define MAX_UDP_PACKET_SIZE 8400 //That's data_size + (num_split_packets*split_overhead). I don't think we'll need it though.
|
|
||||||
#define MAX_NUMBER_OF_SPLIT_PACKETS 6 //MAX_UDP_PACKET_SIZE / SPLIT_UDP_PACKET_SIZE
|
|
||||||
|
|
||||||
//typedefs and enums
|
|
||||||
|
|
||||||
//resources and stuff, here to prevent circular dependencies
|
|
||||||
typedef enum {
|
|
||||||
t_sound = 0,
|
|
||||||
t_skin,
|
|
||||||
t_model,
|
|
||||||
t_decal,
|
|
||||||
t_generic,
|
|
||||||
t_eventscript
|
|
||||||
} resourcetype_t;
|
|
||||||
|
|
||||||
typedef struct _resourceinfo_s{
|
|
||||||
int size;
|
|
||||||
} _resourceinfo_t;
|
|
||||||
typedef struct resourceinfo_s {
|
|
||||||
_resourceinfo_t info[8];
|
|
||||||
} resourceinfo_t;
|
|
||||||
typedef struct resource_s { //0x88
|
|
||||||
|
|
||||||
char szFileName[64]; //00 File name to download/precache.
|
|
||||||
resourcetype_t type; // 40 t_sound, t_skin, t_model, t_decal.
|
|
||||||
int nIndex; // 44 For t_decals
|
|
||||||
int nDownloadSize; // 48 Size in Bytes if this must be downloaded.
|
|
||||||
unsigned char ucFlags;
|
|
||||||
|
|
||||||
// For handling client to client resource propagation
|
|
||||||
unsigned char rgucMD5_hash[16]; // 4d To determine if we already have it.
|
|
||||||
unsigned char playernum; // 5d Which player index this resource is associated with, if it's a custom resource.
|
|
||||||
|
|
||||||
unsigned char rguc_reserved[32]; // 5e For future expansion
|
|
||||||
struct resource_s *pNext; // 80 Next in chain.
|
|
||||||
struct resource_s *pPrev; // 84
|
|
||||||
} resource_t;
|
|
||||||
typedef struct customization_s {
|
|
||||||
|
|
||||||
qboolean bInUse; // 00 Is this customization in use;
|
|
||||||
resource_t resource; // 04 The resource_t for this customization
|
|
||||||
qboolean bTranslated; // 8c Has the raw data been translated into a useable format?
|
|
||||||
//160 // (e.g., raw decal .wad make into texture_t *)
|
|
||||||
int nUserData1; // 90 Customization specific data
|
|
||||||
int nUserData2; // 94 Customization specific data (seems like a size for decals)
|
|
||||||
void *pInfo; // 98 Buffer that holds the data structure that references the data (e.g., the cachewad_t)
|
|
||||||
void *pBuffer; // 9c Buffer that holds the data for the customization (the raw .wad data)
|
|
||||||
struct customization_s *pNext; // A0 Next in chain
|
|
||||||
} customization_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
|
|
||||||
NA_UNUSED,
|
|
||||||
NA_LOOPBACK,
|
|
||||||
NA_BROADCAST,
|
|
||||||
NA_IP,
|
|
||||||
NA_IPX,
|
|
||||||
NA_IPX_BROADCAST,
|
|
||||||
} netadrtype_t;
|
|
||||||
typedef enum {
|
|
||||||
|
|
||||||
NS_CLIENT,
|
|
||||||
NS_SERVER,
|
|
||||||
NS_Unknown2
|
|
||||||
} netsrc_t;
|
|
||||||
typedef enum {
|
|
||||||
|
|
||||||
force_exactfile, // File on client must exactly match server's file
|
|
||||||
force_model_samebounds, // For model files only, the geometry must fit in the same bbox
|
|
||||||
force_model_specifybounds, // For model files only, the geometry must fit in the specified bbox
|
|
||||||
force_model_specifybounds_if_avail, // For Steam model files only, the geometry must fit in the specified bbox (if the file is available)
|
|
||||||
} FORCE_TYPE;
|
|
||||||
|
|
||||||
typedef struct netadr_s { //sizeof 20, 0x14. This struct cannot be modified (damnation) for IPv6 support--mods use it.
|
|
||||||
|
|
||||||
//The question on my mind is how can we fit an IPv6 address in here without breaking mods.
|
|
||||||
netadrtype_t type;
|
|
||||||
unsigned char ip[4]; //must be network order
|
|
||||||
unsigned char ipx[10]; //HA-HAHAHAHAHAhahahaha still need it for padding
|
|
||||||
unsigned short port;
|
|
||||||
} netadr_t;
|
|
||||||
|
|
||||||
//This is all under my control.
|
|
||||||
typedef struct splitpacket_s {
|
|
||||||
|
|
||||||
netadr_t SendingHost;
|
|
||||||
uint32 SequenceNumber;
|
|
||||||
unsigned int TotalChunks;
|
|
||||||
unsigned int ReceivedChunks; //actually bit checks
|
|
||||||
unsigned int CurrentSize;
|
|
||||||
unsigned int offset;
|
|
||||||
byte data[MAX_UDP_PACKET_DATA_SIZE];
|
|
||||||
} splitpacket_t;
|
|
||||||
typedef struct splitpacket_header_s {
|
|
||||||
|
|
||||||
uint32 feffffff;
|
|
||||||
uint32 SequenceNumber;
|
|
||||||
BYTE _4_packetnum4_packettotal; //Four bits are for the packet's ID, four for the total number of packets. IDs start at 0, so the last packet would be like 3|4 not 3|3.
|
|
||||||
BYTE padding1;
|
|
||||||
BYTE padding2;
|
|
||||||
BYTE padding3; //round it out, make sure these align properly
|
|
||||||
} splitpacket_header_t;
|
|
||||||
|
|
||||||
typedef struct event_args_s { //0x48 SDK, matches the DELTA for g_EventDataDefinition (aka event_t)
|
|
||||||
|
|
||||||
int flags; //00
|
|
||||||
// Transmitted
|
|
||||||
int entindex; //04
|
|
||||||
float origin[3]; //08
|
|
||||||
float angles[3]; //14
|
|
||||||
float velocity[3]; //20 not transmitted?
|
|
||||||
|
|
||||||
int ducking; //2c
|
|
||||||
float fparam1; //30
|
|
||||||
float fparam2;
|
|
||||||
int iparam1;
|
|
||||||
int iparam2;
|
|
||||||
int bparam1; //40
|
|
||||||
int bparam2; //44
|
|
||||||
} event_args_t;
|
|
||||||
typedef struct event_info_s { //SDK 0x58
|
|
||||||
|
|
||||||
unsigned short index; //00 // 0 implies not in use
|
|
||||||
short packet_index; //02 // Use data from state info for entity in delta_packet . -1 implies separate info based on event
|
|
||||||
// parameter signature
|
|
||||||
short entity_index; //04 // The edict this event is associated with
|
|
||||||
float fire_time; //08 // if non-zero, the time when the event should be fired ( fixed up on the client )
|
|
||||||
|
|
||||||
event_args_t args; //0c sizeof(0x48)
|
|
||||||
int flags; //54 // Reliable or not, etc.
|
|
||||||
} event_info_t;
|
|
||||||
|
|
||||||
typedef struct ConsistencyData_s { //0x2C
|
|
||||||
|
|
||||||
const char * name;
|
|
||||||
int32 padding04;
|
|
||||||
int32 padding08;
|
|
||||||
int32 padding0C;
|
|
||||||
FORCE_TYPE padding10_force_state; //10
|
|
||||||
vec3_t mins, maxs;
|
|
||||||
} ConsistencyData_t;
|
|
||||||
|
|
||||||
typedef struct entity_state_s { //SDK //0x154
|
|
||||||
|
|
||||||
// Fields which are filled in by routines outside of delta compression
|
|
||||||
int entityType; //00
|
|
||||||
// Index into cl_entities array for this entity.
|
|
||||||
int number;
|
|
||||||
float msg_time;
|
|
||||||
|
|
||||||
// Message number last time the player/entity state was updated.
|
|
||||||
int messagenum;
|
|
||||||
|
|
||||||
// Fields which can be transitted and reconstructed over the network stream
|
|
||||||
vec3_t origin; //10
|
|
||||||
vec3_t angles; //1c
|
|
||||||
|
|
||||||
int modelindex; //28
|
|
||||||
int sequence; //2c
|
|
||||||
float frame;
|
|
||||||
int colormap;
|
|
||||||
short skin;
|
|
||||||
short solid;
|
|
||||||
int effects;
|
|
||||||
float scale;
|
|
||||||
|
|
||||||
byte eflags; //44
|
|
||||||
|
|
||||||
// Render information
|
|
||||||
int rendermode;
|
|
||||||
int renderamt;
|
|
||||||
color24_t rendercolor;
|
|
||||||
int renderfx;
|
|
||||||
|
|
||||||
int movetype;
|
|
||||||
float animtime; //5c
|
|
||||||
float framerate;
|
|
||||||
int body;
|
|
||||||
byte controller[4];
|
|
||||||
byte blending[4];
|
|
||||||
vec3_t velocity; //70
|
|
||||||
|
|
||||||
// Send bbox down to client for use during prediction.
|
|
||||||
vec3_t mins; //7c
|
|
||||||
vec3_t maxs; //88
|
|
||||||
|
|
||||||
int aiment; //94
|
|
||||||
// If owned by a player, the index of that player ( for projectiles ).
|
|
||||||
int owner;
|
|
||||||
|
|
||||||
// Friction, for prediction.
|
|
||||||
float friction; //9c
|
|
||||||
// Gravity multiplier
|
|
||||||
float gravity;
|
|
||||||
|
|
||||||
// PLAYER SPECIFIC
|
|
||||||
int team;
|
|
||||||
int playerclass;
|
|
||||||
int health;
|
|
||||||
qboolean spectator;
|
|
||||||
int weaponmodel;
|
|
||||||
int gaitsequence;
|
|
||||||
// If standing on conveyor, e.g.
|
|
||||||
vec3_t basevelocity; //bc
|
|
||||||
// Use the crouched hull, or the regular player hull.
|
|
||||||
int usehull; //c8
|
|
||||||
// Latched buttons last time state updated.
|
|
||||||
int oldbuttons;
|
|
||||||
// -1 = in air, else pmove entity number
|
|
||||||
int onground;
|
|
||||||
int iStepLeft;
|
|
||||||
// How fast we are falling
|
|
||||||
float flFallVelocity;
|
|
||||||
|
|
||||||
float fov; //dc
|
|
||||||
int weaponanim;
|
|
||||||
|
|
||||||
// Parametric movement overrides
|
|
||||||
vec3_t startpos; //e4
|
|
||||||
vec3_t endpos; //f0
|
|
||||||
float impacttime; //fc
|
|
||||||
float starttime;
|
|
||||||
|
|
||||||
// For mods
|
|
||||||
int iuser1;
|
|
||||||
int iuser2;
|
|
||||||
int iuser3;
|
|
||||||
int iuser4;
|
|
||||||
float fuser1;
|
|
||||||
float fuser2;
|
|
||||||
float fuser3;
|
|
||||||
float fuser4;
|
|
||||||
vec3_t vuser1; //124
|
|
||||||
vec3_t vuser2; //130
|
|
||||||
vec3_t vuser3; //13c
|
|
||||||
vec3_t vuser4; //148
|
|
||||||
} entity_state_t;
|
|
||||||
typedef struct packet_entities_s { //28
|
|
||||||
|
|
||||||
//float servertime; //??
|
|
||||||
//int num_entities; //??
|
|
||||||
//int max_entities; //??
|
|
||||||
uint32 max_entities; //num, max, it's really hard to tell right now.
|
|
||||||
uint32 padding04;
|
|
||||||
uint32 padding08;
|
|
||||||
uint32 padding0c;
|
|
||||||
uint32 padding10;
|
|
||||||
uint32 padding14;
|
|
||||||
uint32 padding18;
|
|
||||||
uint32 padding1c;
|
|
||||||
uint32 padding20;
|
|
||||||
entity_state_t *entities; //24
|
|
||||||
} packet_entities_t;
|
|
||||||
|
|
||||||
typedef struct OddEntityContainer_s { //This is not of variable size. This is the whole thing.
|
|
||||||
|
|
||||||
uint32 padding00; //a counter
|
|
||||||
int32 padding04[0x40]; //string_ts I think, so basically offset char pointers.
|
|
||||||
entity_state_t padding104[0x40];
|
|
||||||
} OddEntityContainer_t;
|
|
||||||
|
|
||||||
typedef struct clientdata_s {
|
|
||||||
|
|
||||||
vec3_t origin; //00
|
|
||||||
vec3_t velocity; //0c
|
|
||||||
|
|
||||||
int viewmodel; //18
|
|
||||||
vec3_t punchangle; //1c
|
|
||||||
int flags; //28
|
|
||||||
int waterlevel; //2c
|
|
||||||
int watertype; //30
|
|
||||||
vec3_t view_ofs; //34
|
|
||||||
float health; //40
|
|
||||||
|
|
||||||
int bInDuck;
|
|
||||||
|
|
||||||
int weapons; // remove?
|
|
||||||
|
|
||||||
int flTimeStepSound;
|
|
||||||
int flDuckTime; //50
|
|
||||||
int flSwimTime;
|
|
||||||
int waterjumptime;
|
|
||||||
|
|
||||||
float maxspeed; //5c
|
|
||||||
|
|
||||||
float fov; //60
|
|
||||||
int weaponanim;
|
|
||||||
|
|
||||||
int m_iId;
|
|
||||||
int ammo_shells;
|
|
||||||
int ammo_nails; //70
|
|
||||||
int ammo_cells;
|
|
||||||
int ammo_rockets;
|
|
||||||
float m_flNextAttack;
|
|
||||||
|
|
||||||
int tfstate; //80
|
|
||||||
|
|
||||||
int pushmsec;
|
|
||||||
|
|
||||||
int deadflag; //88
|
|
||||||
|
|
||||||
char physinfo[0x100]; //8c, MAX_PHYSINFO_STRING
|
|
||||||
|
|
||||||
// For mods
|
|
||||||
int iuser1; //18c
|
|
||||||
int iuser2;
|
|
||||||
int iuser3;
|
|
||||||
int iuser4;
|
|
||||||
float fuser1; //19c
|
|
||||||
float fuser2;
|
|
||||||
float fuser3;
|
|
||||||
float fuser4;
|
|
||||||
vec3_t vuser1; //1ac
|
|
||||||
vec3_t vuser2; //1b8
|
|
||||||
vec3_t vuser3; //1c4
|
|
||||||
vec3_t vuser4; //1d0
|
|
||||||
} clientdata_t;
|
|
||||||
typedef struct weapon_data_s { //0x58 SDK
|
|
||||||
|
|
||||||
int m_iId; //00
|
|
||||||
int m_iClip;
|
|
||||||
|
|
||||||
float m_flNextPrimaryAttack;
|
|
||||||
float m_flNextSecondaryAttack;
|
|
||||||
float m_flTimeWeaponIdle; //10
|
|
||||||
|
|
||||||
int m_fInReload;
|
|
||||||
int m_fInSpecialReload;
|
|
||||||
float m_flNextReload;
|
|
||||||
float m_flPumpTime; //20
|
|
||||||
float m_fReloadTime;
|
|
||||||
|
|
||||||
float m_fAimedDamage;
|
|
||||||
float m_fNextAimBonus;
|
|
||||||
int m_fInZoom; //30
|
|
||||||
int m_iWeaponState;
|
|
||||||
|
|
||||||
int iuser1;
|
|
||||||
int iuser2;
|
|
||||||
int iuser3; //40
|
|
||||||
int iuser4;
|
|
||||||
float fuser1;
|
|
||||||
float fuser2;
|
|
||||||
float fuser3; //50
|
|
||||||
float fuser4;
|
|
||||||
} weapon_data_t;
|
|
||||||
typedef struct client_frame_s { //0x1810
|
|
||||||
|
|
||||||
double sent_time; //confirmed
|
|
||||||
float ping_time; //confirmed
|
|
||||||
clientdata_t clientdata_0C; //0x0c, size if 0x1DC
|
|
||||||
weapon_data_t weapondata_1e8[0x20]; //1e8, size 0x58, total is B00
|
|
||||||
char dragons[0xB00]; //CE8
|
|
||||||
|
|
||||||
packet_entities_t entities; //17E8 + 0x28 = 1810
|
|
||||||
|
|
||||||
} client_frame_t;
|
|
||||||
|
|
||||||
typedef struct loopmsg_s {
|
|
||||||
|
|
||||||
BYTE data[MAX_UDP_PACKET_DATA_SIZE];
|
|
||||||
unsigned int datalen;
|
|
||||||
} loopmsg_t;
|
|
||||||
|
|
||||||
typedef struct loopback_s {
|
|
||||||
|
|
||||||
loopmsg_t msgs[MAX_LOOPBACK];
|
|
||||||
int get;
|
|
||||||
int send;
|
|
||||||
} loopback_t;
|
|
||||||
typedef struct global_net_messages_s {
|
|
||||||
|
|
||||||
struct global_net_messages_s *next;
|
|
||||||
qboolean DoNotFree;
|
|
||||||
BYTE *data;
|
|
||||||
netadr_t from;
|
|
||||||
int cursize;//or is it maxsize?
|
|
||||||
} global_net_messages_t;
|
|
||||||
|
|
||||||
typedef struct fragbuf_s { //0x6A8 bytes
|
|
||||||
|
|
||||||
struct fragbuf_s *next; //def +0
|
|
||||||
uint32 ShortID; //It is confirmed that the high 16 bits are a counter that act as sequence numbers.
|
|
||||||
sizebuf_t buffer; //20 0x14
|
|
||||||
byte packetsizedbuffer[1400]; //+28
|
|
||||||
int boolean1; //+1428
|
|
||||||
int boolean2;
|
|
||||||
char padding[260]; //+1436, this appears to be the exact size
|
|
||||||
int fragoffset; //0x6a0
|
|
||||||
int fragsize;
|
|
||||||
} fragbuf_t;
|
|
||||||
typedef struct fragbufholder_s {
|
|
||||||
|
|
||||||
struct fragbufholder_s *next; //Definite +0
|
|
||||||
int count;
|
|
||||||
fragbuf_t *fragbuf; //Definite +8
|
|
||||||
} fragbufholder_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct flowstruct2_s { //12 bytes.
|
|
||||||
|
|
||||||
int32 padding00;
|
|
||||||
double padding04;
|
|
||||||
|
|
||||||
} flowstruct2_t;
|
|
||||||
typedef struct flowstruct1_s { //404 bytes large
|
|
||||||
|
|
||||||
flowstruct2_t array[32];
|
|
||||||
|
|
||||||
int32 last_received;
|
|
||||||
double padding184;
|
|
||||||
float KBflowrate;
|
|
||||||
float KBflowrateaverage;
|
|
||||||
|
|
||||||
} flowstruct1_t;
|
|
||||||
|
|
||||||
typedef struct netchan_s { //size is 0x2414h.
|
|
||||||
|
|
||||||
netsrc_t socketToUse;
|
|
||||||
netadr_t remote_address;
|
|
||||||
|
|
||||||
unsigned int client_index; //This variable's basically just nice to have around. We never use it.
|
|
||||||
float last_received; //Last received communication.
|
|
||||||
float first_received; //When they connected
|
|
||||||
|
|
||||||
double rate; //Guessed due to proximity in QW struct. Not perfect match.
|
|
||||||
double cleartime; //Almost certain since it's zerod out in clearing.
|
|
||||||
|
|
||||||
//There's an annoying unix/windows discrepancy here--windows insists that
|
|
||||||
//doubles are aligned to an 8 byte boundary, unix 4. Mods don't have
|
|
||||||
//access to netchans though, so we're okay.
|
|
||||||
|
|
||||||
uint32 incoming_sequence;
|
|
||||||
uint32 incoming_acknowledged;
|
|
||||||
uint32 incoming_reliable_acknowledged; //When I think boolean, I think true false. This is one bit, but not true/false.
|
|
||||||
uint32 incoming_reliable_sequence; //one bit, usually inverse of above.
|
|
||||||
|
|
||||||
uint32 outgoing_sequence; //frame sequence or something like that.
|
|
||||||
uint32 outgoing_reliable_sequence; //one bit
|
|
||||||
uint32 outgoing_last_reliable_sequence;
|
|
||||||
|
|
||||||
struct client_s * owning_client; //Who owns this netchan. excluding cls, this should always point roughly 28 or so bytes ahead of the netchan.
|
|
||||||
int (*fn_GetFragmentSize)(struct client_s *); //SV_GetFragmentSize
|
|
||||||
|
|
||||||
sizebuf_t netchan_message; //using the name 'message' is bad. message is too common a word.
|
|
||||||
byte netchan_message_buf[0xF98]; //3990 in code, rounded up to 4 byte marker
|
|
||||||
|
|
||||||
int reliable_length; //size of buffer below
|
|
||||||
byte reliable_buf[0xF98];
|
|
||||||
|
|
||||||
fragbufholder_t * padding1FA0[2]; //a linked list. This stuff all seems to be for file transfers.
|
|
||||||
qboolean padding1FA8[2]; //bools
|
|
||||||
uint32 padding1FB0[2];
|
|
||||||
fragbuf_t * padding1FB8[2]; //'packets' to be sent methinks
|
|
||||||
uint32 NumberOfFragbufsIn1FC0[2];
|
|
||||||
uint16 padding1FC8[2];
|
|
||||||
uint16 padding1FCC[2];
|
|
||||||
fragbuf_t * padding1FD0[2];
|
|
||||||
qboolean padding1FD8[2];
|
|
||||||
char filename[0x104];
|
|
||||||
char * TemporaryBuffer;
|
|
||||||
int32 TemporaryBufferSize; //20EC?
|
|
||||||
flowstruct1_t flow[2]; //two elements that are 404 bytes long 0x194
|
|
||||||
|
|
||||||
} netchan_t;
|
|
||||||
|
|
||||||
typedef struct client_s { //20204, 0x4eec
|
|
||||||
|
|
||||||
//There are two working theories on how some of these vars work. It WAS believed
|
|
||||||
//that padding00 was a bitmask and 04 was related to spectating.
|
|
||||||
//Another theory is that the first four ints are bools, 00 04 and 0c of which
|
|
||||||
//are "active" "spawned", and "connected"--but possibly NOT in that order...
|
|
||||||
|
|
||||||
qboolean padding00_used; //Connected is set to 1 before this, so I guess active, not used.
|
|
||||||
int32 padding04;
|
|
||||||
int32 padding08; //this is identified now as a bool signalling the client's need to have ent data sent to it.
|
|
||||||
qboolean padding0C_connected; //confirmed
|
|
||||||
int32 padding10; //custom resources?
|
|
||||||
int32 padding14;
|
|
||||||
int32 padding18;
|
|
||||||
|
|
||||||
netchan_t netchan1C;
|
|
||||||
|
|
||||||
int32 padding2430; //chokecount, maybe.
|
|
||||||
int32 padding2434_delta_sequence;
|
|
||||||
int32 padding2438_IsFakeClient;
|
|
||||||
int32 padding243C_proxy;
|
|
||||||
usercmd_t padding2440; //0x34
|
|
||||||
double padding2474_LastCommandTime; //These three were quickly guessed at.
|
|
||||||
double padding247C_LastRunTime;
|
|
||||||
double padding2484_NextRunTime;
|
|
||||||
|
|
||||||
float ping;
|
|
||||||
float packet_loss;
|
|
||||||
int32 padding2494;
|
|
||||||
int32 padding2498;
|
|
||||||
double padding249C_TimeOfNextPingCalc;
|
|
||||||
double padding24A4; //deals with time bases
|
|
||||||
sizebuf_t sizebuf24AC; //datagram
|
|
||||||
char datagram_buffer[0xFA0];
|
|
||||||
double padding3460_connection_started;
|
|
||||||
double next_update_time;
|
|
||||||
double cl_updaterate;
|
|
||||||
int32 padding3478_SendNextTick;
|
|
||||||
int32 padding347C_SkipNextTick;
|
|
||||||
client_frame_t * padding3480_frames;
|
|
||||||
event_info_t events[0x40]; //3484 The sizes match
|
|
||||||
edict_t * padding4A84; //One of these refers to the client's edict. I'll sort it out one of these days.
|
|
||||||
const edict_t * padding4A88; //Okay, it's later. It seems this is a 'target' or 'destination' or something. It might also be a camera, like the screens in cs_assault you look through.
|
|
||||||
int32 padding4A8C_PlayerUID; //Nothing to do with authing. Just the order clients connected in.
|
|
||||||
int authentication_method;
|
|
||||||
uint32 authentication_WonID; //WonID!
|
|
||||||
// int64 paddingID64;
|
|
||||||
// int32 padding4AA0;
|
|
||||||
char InfoKeyBuffer[0x100]; //called userinfo actually
|
|
||||||
uint32 padding4BA4;
|
|
||||||
float padding4BA8;
|
|
||||||
char authentication_CD_key[0x40]; //This seems to hold the CD key, in printed hex.
|
|
||||||
char PlayerName[0x20]; //0x4bec
|
|
||||||
int32 topcolor;//0x4c0c
|
|
||||||
int32 bottomcolor;
|
|
||||||
int32 padding4C14; //unused
|
|
||||||
resource_t resource4C18;
|
|
||||||
resource_t resource4CA0;
|
|
||||||
int32 padding4D28; //unused
|
|
||||||
int32 padding4D2C; //HasPropagatedCustomResources (like the decal)
|
|
||||||
customization_t padding4D30; //sizeof(a4)
|
|
||||||
CRC32_t local_map_CRC; //Partly a guess, but makes sense.
|
|
||||||
qboolean cl_lw; //cl_lw = 0 means servers confirm weaponfire.
|
|
||||||
qboolean cl_lc; //lag compensation
|
|
||||||
char UnknownStruct4DE0[0x100]; //identified as physinfo
|
|
||||||
int32 padding4EE0;
|
|
||||||
int32 padding4EE4; //bits?
|
|
||||||
int32 padding4EE8;
|
|
||||||
} client_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct client_static_s { //basically global_cls, mostly only used by the client
|
|
||||||
|
|
||||||
// Current state. We KNOW this is +0.
|
|
||||||
cactive_t state;
|
|
||||||
netchan_t netchan; //Not 100% confirmed (will be difficult since inline)
|
|
||||||
|
|
||||||
char padding[0x1034];
|
|
||||||
|
|
||||||
int padding340C;
|
|
||||||
char padding5[0x104]; //3410
|
|
||||||
char paddingstr[0x40]; //3514
|
|
||||||
char padding4[0x800]; //3554
|
|
||||||
char userinfo[0x104]; //3d54
|
|
||||||
char padding2[0x208];
|
|
||||||
int padding4060;
|
|
||||||
//eax+4064 = demoplayback in QW, matches up sort've.
|
|
||||||
enum { DPB_0, DPB_1, DPB_2, DPB_3 } demoplayback; //int for all intents.
|
|
||||||
int padding4068;
|
|
||||||
char padding3[0x320];
|
|
||||||
int padding438C;
|
|
||||||
|
|
||||||
} client_static_t;
|
|
||||||
//global_sv
|
|
||||||
typedef struct server_s { //sizeof 0x4640C
|
|
||||||
|
|
||||||
qboolean active; //Confirmed +0, false when server is going down
|
|
||||||
int32 padding04; //looks to be 'pause'
|
|
||||||
int32 padding08;
|
|
||||||
double time0c;
|
|
||||||
double time14;
|
|
||||||
int lastcheck;
|
|
||||||
double lastchecktime; //20
|
|
||||||
//name held "undertow" when debugging.
|
|
||||||
char name[64]; //28 A character array is known to be +28, called by SVC_info. The size oft he array might be 32 tho.
|
|
||||||
char name2[0x40]; //68
|
|
||||||
char name3[0x40]; //a8
|
|
||||||
char name4[0x40];//e8
|
|
||||||
|
|
||||||
model_t *worldmodel;
|
|
||||||
CRC32_t map_CRC;
|
|
||||||
char usedpadding[0x10]; //client DLL digest
|
|
||||||
|
|
||||||
resource_t ConsistencyData[0x500]; //140. 0x88 * 0x500 = 0x2A800
|
|
||||||
uint32 padding2A940_SomeMaxValue; //2A940, it's the total consistency data things. And it's only allowed to use 0x0C bytes.
|
|
||||||
|
|
||||||
ConsistencyData_t padding2A944[0x200]; //2a944
|
|
||||||
int32 padding30144_SomeTotalValue; //30144
|
|
||||||
|
|
||||||
char *model_precache[MAX_MODELS]; //30148 +800
|
|
||||||
model_t *models[512]; // 30948, unconfirmed array number.
|
|
||||||
char padding31148[0x200]; // 200 character booleans?
|
|
||||||
|
|
||||||
struct TemporaryEventStructure {
|
|
||||||
|
|
||||||
short int index;
|
|
||||||
const char * str;
|
|
||||||
int size;
|
|
||||||
void * mem;
|
|
||||||
} padding31348[0x100]; //This is now known to be 0x100 0x10 byte structs related to events.
|
|
||||||
|
|
||||||
char *sound_precache[MAX_SOUNDS]; //32348
|
|
||||||
uint16 padding32B48[0x0400]; //index table, seems to be one short shorter than this.
|
|
||||||
|
|
||||||
uint32 padding33348;
|
|
||||||
char *generic_precache[MAX_GNERIC]; //3334c
|
|
||||||
|
|
||||||
char padding33B4C[0x200][0x40]; //Strings. An array of strings.
|
|
||||||
|
|
||||||
uint32 padding3bb4c; //a count variable for the number of used strings.
|
|
||||||
char *padding3BB50[0x40]; //size is guessed at, written in SV_WriteSpawn
|
|
||||||
uint32 num_edicts; //3bc50
|
|
||||||
uint32 max_edicts;
|
|
||||||
edict_t *edicts; //3bc58
|
|
||||||
entity_state_t * edstates;
|
|
||||||
OddEntityContainer_t * padding3bc60_struct; //used in writedeltaheader. It's a large struct that's largely a mystery.
|
|
||||||
//mystery struct: +0 = count, +4 = int array?, +104 = entity_state_t[]
|
|
||||||
|
|
||||||
uint32 padding3bc64;
|
|
||||||
sizebuf_t reliable_datagram; //3bc68
|
|
||||||
char reliablebuffer[0xFA0]; //3bc7C //maybe it's not so reliable. Ah well.
|
|
||||||
|
|
||||||
sizebuf_t sizebuf3CC1C; //3cc1c reliable buffer msg_all
|
|
||||||
char OtherReliableBuffer[0xFA0]; //3cc30
|
|
||||||
|
|
||||||
sizebuf_t sizebuf3dbd0_multicast; //3DBD0 multicast
|
|
||||||
char MulticastBuffer[0x400]; //3dbe4 obviously used in the sizebuf.
|
|
||||||
sizebuf_t spectator_datagram; //3DFE4
|
|
||||||
char SpectatorBuffer[0x400]; //3dff8
|
|
||||||
sizebuf_t signon_datagram; //3e3f8 signon
|
|
||||||
char SignonBuffer[0x8000]; //3e40c
|
|
||||||
} server_t;
|
|
||||||
//From QW, global_svs
|
|
||||||
typedef struct server_static_s { //sizeof 0xf4, possibly 0x100
|
|
||||||
|
|
||||||
int pad00; //This var somehow indicates the server's running state.
|
|
||||||
client_t * clients;
|
|
||||||
unsigned int allocated_client_slots; //+08
|
|
||||||
unsigned int total_client_slots; //+0C
|
|
||||||
unsigned int ServerCount;
|
|
||||||
uint32 padding14; //flags
|
|
||||||
uint32 padding18;
|
|
||||||
uint32 padding1C;
|
|
||||||
uint32 padding20;
|
|
||||||
uint32 padding24;
|
|
||||||
uint32 padding28;
|
|
||||||
uint32 padding2C;
|
|
||||||
uint32 padding30;
|
|
||||||
uint32 padding34;
|
|
||||||
|
|
||||||
double padding38;
|
|
||||||
double padding40;
|
|
||||||
|
|
||||||
uint32 padding48; //This to 7C is all some struct.
|
|
||||||
uint32 padding4C;
|
|
||||||
uint32 padding50;
|
|
||||||
float padding54;
|
|
||||||
float padding58;
|
|
||||||
uint32 padding5C;
|
|
||||||
uint32 padding60;
|
|
||||||
float padding64;
|
|
||||||
float padding68;
|
|
||||||
uint32 padding6C;
|
|
||||||
float padding70;
|
|
||||||
uint32 padding74;
|
|
||||||
float padding78;
|
|
||||||
float padding7C;
|
|
||||||
|
|
||||||
security_module_t module80[4];
|
|
||||||
|
|
||||||
uint32 paddingE0;
|
|
||||||
uint32 paddingE4;
|
|
||||||
uint32 paddingE8; //IsSecure
|
|
||||||
double paddingEC_inittime;
|
|
||||||
uint32 paddingF4;
|
|
||||||
uint32 paddingF8;
|
|
||||||
uint32 paddingFC;
|
|
||||||
/*
|
|
||||||
gametype_e gametype;
|
|
||||||
int spawncount; // number of servers spawned since start,
|
|
||||||
// used to check late spawns
|
|
||||||
|
|
||||||
int socketip;
|
|
||||||
int socketip6;
|
|
||||||
int socketipx;
|
|
||||||
|
|
||||||
#ifdef TCPCONNECT
|
|
||||||
int sockettcp;
|
|
||||||
global_svtcpstream_t *tcpstreams;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
client_t clients[MAX_CLIENTS];
|
|
||||||
int serverflags; // episode completion information
|
|
||||||
|
|
||||||
double last_heartbeat;
|
|
||||||
int heartbeat_sequence;
|
|
||||||
global_svstats_t stats;
|
|
||||||
|
|
||||||
char info[MAX_SERVERINFO_STRING];
|
|
||||||
|
|
||||||
// log messages are used so that fraglog processes can get stats
|
|
||||||
int logsequence; // the message currently being filled
|
|
||||||
double logtime; // time of last swap
|
|
||||||
sizebuf_t log[2];
|
|
||||||
qbyte log_buf[2][MAX_DATAGRAM];
|
|
||||||
|
|
||||||
challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting
|
|
||||||
|
|
||||||
bannedips_t *bannedips;
|
|
||||||
filteredips_t *filteredips;
|
|
||||||
|
|
||||||
char progsnames[MAX_PROGS][32];
|
|
||||||
progsnum_t progsnum[MAX_PROGS];
|
|
||||||
int numprogs;
|
|
||||||
|
|
||||||
#ifdef PROTOCOLEXTENSIONS
|
|
||||||
unsigned long fteprotocolextensions;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
qboolean demoplayback;
|
|
||||||
qboolean demorecording;
|
|
||||||
qboolean msgfromdemo;
|
|
||||||
|
|
||||||
int language; //the server operators language
|
|
||||||
|
|
||||||
levelcache_t *levcache;
|
|
||||||
*/
|
|
||||||
} server_static_t;
|
|
||||||
|
|
||||||
|
|
||||||
//globals
|
|
||||||
extern client_static_t global_cls;
|
|
||||||
extern server_static_t global_svs;
|
|
||||||
extern server_t global_sv;
|
|
||||||
|
|
||||||
extern client_t * global_host_client;
|
|
||||||
|
|
||||||
extern netadr_t global_net_local_adr;
|
|
||||||
extern netadr_t global_net_from;
|
|
||||||
extern sizebuf_t global_net_message;
|
|
||||||
extern int global_net_drop;
|
|
||||||
extern qboolean global_noip;
|
|
||||||
|
|
||||||
//functions
|
|
||||||
void NET_Init();
|
|
||||||
void NET_SendPacket(netsrc_t, int, byte *, netadr_t);
|
|
||||||
qboolean NET_GetPacket(netsrc_t);
|
|
||||||
qboolean NET_CompareAdr(netadr_t, netadr_t);
|
|
||||||
qboolean NET_StringToAdr(const char *, netadr_t *);
|
|
||||||
char * NET_AdrToString(netadr_t);
|
|
||||||
int NET_AdrToStringThread(netadr_t, char *, int);
|
|
||||||
qboolean NET_IsConfigured();
|
|
||||||
void NET_Config(qboolean);
|
|
||||||
qboolean NET_CompareBaseAdr(netadr_t, netadr_t);
|
|
||||||
qboolean NET_CompareClassBAdr(netadr_t, netadr_t);
|
|
||||||
qboolean NET_IsLocalAddress(netadr_t);
|
|
||||||
void NET_Shutdown();
|
|
||||||
|
|
||||||
void Netchan_Init();
|
|
||||||
void Netchan_Setup(netsrc_t, netchan_t *, netadr_t, int, client_t *, void *);
|
|
||||||
qboolean Netchan_CanPacket(netchan_t *);
|
|
||||||
void Netchan_Transmit(netchan_t *, int, char *);
|
|
||||||
void Netchan_Clear(netchan_t *);
|
|
||||||
void Netchan_CreateFragments(qboolean, netchan_t *, sizebuf_t *);
|
|
||||||
void Netchan_FragSend(netchan_t *);
|
|
||||||
qboolean Netchan_IncomingReady(netchan_t *);
|
|
||||||
int Netchan_CopyFileFragments(netchan_t *);
|
|
||||||
int Netchan_CopyNormalFragments(netchan_t *);
|
|
||||||
qboolean Netchan_Process(netchan_t *);
|
|
||||||
void Netchan_OutOfBandPrint(netsrc_t, netadr_t, char *, ...);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
/* The Quakeworld code doesn't ever call memcpy directly. Instead it
|
|
||||||
// calls q_memcpy, which is #defined into regular old memcpy. Other
|
|
||||||
// mem functions get this treatment too. I'm guessing it's so they can do
|
|
||||||
// a bunch of ASSERTs in debugging, so I'll keep it around. Less for me
|
|
||||||
// to write anyway.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_Q_MEMFUNCTIONS_HEADER
|
|
||||||
#define OSHLDS_Q_MEMFUNCTIONS_HEADER
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
//Basic mem functions
|
|
||||||
#define Q_memset(d, f, c) memset((d), (f), (c))
|
|
||||||
#define Q_memcpy(d, s, c) memmove((d), (s), (c)) //A couple times I noticed memcpy was being used where memmove should've been. This is a hack.
|
|
||||||
#define Q_memmove(d, s, c) memmove((d), (s), (c))
|
|
||||||
#define Q_memcmp(m1, m2, c) memcmp((m1), (m2), (c))
|
|
||||||
#define Q_strcpy(d, s) strcpy((d), (s))
|
|
||||||
#define Q_strncpy(d, s, n) strncpy((d), (s), (n))
|
|
||||||
#define Q_strlen(s) strlen(s)
|
|
||||||
#define Q_strstr(s1, s2) strstr(s1, s2)
|
|
||||||
|
|
||||||
#define Q_strrchr(s, c) strrchr((s), (c))
|
|
||||||
#define Q_strcat(d, s) strcat((d), (s))
|
|
||||||
#define Q_strcmp(s1, s2) strcmp((s1), (s2))
|
|
||||||
#define Q_strcmp_ptr strcmp
|
|
||||||
#define Q_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
|
|
||||||
#if(defined(_MSC_VER) && _MSC_VER <= 1200) //means an old version of VS. I know 6.0 requires this.
|
|
||||||
#define Q_strcasecmp(s1, s2) stricmp((s1), (s2))
|
|
||||||
#else
|
|
||||||
#define Q_strcasecmp(s1, s2) strcasecmp((s1), (s2))
|
|
||||||
#endif
|
|
||||||
#define Q_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
|
|
||||||
|
|
||||||
//The mallocs. Can be handy for using debug malloc libs.
|
|
||||||
#define Q_Malloc(s1) malloc(s1)
|
|
||||||
#define Q_Realloc(s1, s2) realloc(s1, s2)
|
|
||||||
#define Q_Calloc(s1, s2) calloc(s1, s2)
|
|
||||||
#define Q_Free(s1) free(s1)
|
|
||||||
#define Q_Strdup(s1) strdup(s1)
|
|
||||||
|
|
||||||
//These two were actually written out. Do they differ from the standard calls?
|
|
||||||
#define Q_atoi(x) atoi(x)
|
|
||||||
#define Q_atof(x) atof(x)
|
|
||||||
|
|
||||||
//THESE I added because I kept using them even though they're not really handy to override.
|
|
||||||
#define Q_sprintf sprintf
|
|
||||||
|
|
||||||
#if((defined(_MSC_VER) && _MSC_VER <= 1200) || __BORLANDC__)
|
|
||||||
#define Q_snprintf _snprintf //Turns out this one IS handy.
|
|
||||||
#define Q_vsnprintf _vsnprintf
|
|
||||||
#else
|
|
||||||
#define Q_snprintf snprintf
|
|
||||||
#define Q_vsnprintf vsnprintf
|
|
||||||
#endif
|
|
||||||
#define Q_strchr strchr
|
|
||||||
#define Q_strtok strtok
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,261 +0,0 @@
|
|||||||
/*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_R_HEADER
|
|
||||||
#define OSHLDS_R_HEADER
|
|
||||||
|
|
||||||
#include "VecMath.h"
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
|
|
||||||
//studio.h stuff
|
|
||||||
#define STUDIO_VERSION 0x0A
|
|
||||||
|
|
||||||
#define MAXSTUDIOTRIANGLES 20000
|
|
||||||
#define MAXSTUDIOVERTS 2048
|
|
||||||
#define MAXSTUDIOSEQUENCES 256 // total animation sequences
|
|
||||||
#define MAXSTUDIOSKINS 100 // total textures
|
|
||||||
#define MAXSTUDIOSRCBONES 512 // bones allowed at source movement
|
|
||||||
#define MAXSTUDIOBONES 128 // total bones actually used
|
|
||||||
#define MAXSTUDIOMODELS 32 // sub-models per model
|
|
||||||
#define MAXSTUDIOBODYPARTS 32
|
|
||||||
#define MAXSTUDIOGROUPS 16
|
|
||||||
#define MAXSTUDIOANIMATIONS 512 // per sequence
|
|
||||||
#define MAXSTUDIOMESHES 256
|
|
||||||
#define MAXSTUDIOEVENTS 1024
|
|
||||||
#define MAXSTUDIOPIVOTS 256
|
|
||||||
#define MAXSTUDIOCONTROLLERS 8
|
|
||||||
|
|
||||||
// lighting options
|
|
||||||
#define STUDIO_NF_FLATSHADE 0x0001
|
|
||||||
#define STUDIO_NF_CHROME 0x0002
|
|
||||||
#define STUDIO_NF_FULLBRIGHT 0x0004
|
|
||||||
|
|
||||||
// motion flags
|
|
||||||
#define STUDIO_X 0x0001
|
|
||||||
#define STUDIO_Y 0x0002
|
|
||||||
#define STUDIO_Z 0x0004
|
|
||||||
#define STUDIO_XR 0x0008
|
|
||||||
#define STUDIO_YR 0x0010
|
|
||||||
#define STUDIO_ZR 0x0020
|
|
||||||
#define STUDIO_LX 0x0040
|
|
||||||
#define STUDIO_LY 0x0080
|
|
||||||
#define STUDIO_LZ 0x0100
|
|
||||||
#define STUDIO_AX 0x0200
|
|
||||||
#define STUDIO_AY 0x0400
|
|
||||||
#define STUDIO_AZ 0x0800
|
|
||||||
#define STUDIO_AXR 0x1000
|
|
||||||
#define STUDIO_AYR 0x2000
|
|
||||||
#define STUDIO_AZR 0x4000
|
|
||||||
#define STUDIO_TYPES 0x7FFF
|
|
||||||
#define STUDIO_RLOOP 0x8000 // controller that wraps shortest distance
|
|
||||||
|
|
||||||
// sequence flags
|
|
||||||
#define STUDIO_LOOPING 0x0001
|
|
||||||
|
|
||||||
// bone flags
|
|
||||||
#define STUDIO_HAS_NORMALS 0x0001
|
|
||||||
#define STUDIO_HAS_VERTICES 0x0002
|
|
||||||
#define STUDIO_HAS_BBOX 0x0004
|
|
||||||
#define STUDIO_HAS_CHROME 0x0008 // if any of the textures have chrome on them
|
|
||||||
|
|
||||||
#define RAD_TO_STUDIO (32768.0/M_PI)
|
|
||||||
#define STUDIO_TO_RAD (M_PI/32768.0)
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct studiohdr_s { //F4
|
|
||||||
|
|
||||||
int id;
|
|
||||||
int version; //04
|
|
||||||
|
|
||||||
char name[64]; //08
|
|
||||||
int length; //48
|
|
||||||
|
|
||||||
vec3_t eyeposition; // ideal eye position
|
|
||||||
vec3_t min; // ideal movement hull size
|
|
||||||
vec3_t max;
|
|
||||||
|
|
||||||
vec3_t bbmin; // clipping bounding box
|
|
||||||
vec3_t bbmax;
|
|
||||||
|
|
||||||
int flags; //88
|
|
||||||
|
|
||||||
int numbones; // bones
|
|
||||||
int boneindex;
|
|
||||||
|
|
||||||
int numbonecontrollers; // bone controllers
|
|
||||||
int bonecontrollerindex;
|
|
||||||
|
|
||||||
int numhitboxes; // complex bounding boxes
|
|
||||||
int hitboxindex;
|
|
||||||
|
|
||||||
int numseq; // A4 animation sequences
|
|
||||||
int seqindex;
|
|
||||||
|
|
||||||
int numseqgroups; // demand loaded sequences
|
|
||||||
int seqgroupindex;
|
|
||||||
|
|
||||||
int numtextures; // raw textures
|
|
||||||
int textureindex;
|
|
||||||
int texturedataindex; //BC?
|
|
||||||
|
|
||||||
int numskinref; // replaceable textures
|
|
||||||
int numskinfamilies;
|
|
||||||
int skinindex;
|
|
||||||
|
|
||||||
int numbodyparts; //CC
|
|
||||||
int bodypartindex;
|
|
||||||
|
|
||||||
int numattachments; // queryable attachable points
|
|
||||||
int attachmentindex;
|
|
||||||
|
|
||||||
int soundtable;
|
|
||||||
int soundindex;
|
|
||||||
int soundgroups;
|
|
||||||
int soundgroupindex;
|
|
||||||
|
|
||||||
int numtransitions; // animation node to animation node transition graph
|
|
||||||
int transitionindex;
|
|
||||||
} studiohdr_t;
|
|
||||||
typedef struct studioseqhdr_s {
|
|
||||||
|
|
||||||
int id;
|
|
||||||
int version;
|
|
||||||
|
|
||||||
char name[64];
|
|
||||||
int length;
|
|
||||||
} studioseqhdr_t;
|
|
||||||
typedef struct mstudiobone_s { //0x70
|
|
||||||
char name[32]; // 00 bone name for symbolic links
|
|
||||||
int parent; // 20 parent bone
|
|
||||||
int flags; // 24 ??
|
|
||||||
int bonecontroller[6]; // 28 bone controller index, -1 == none
|
|
||||||
float value[6]; // 40 default DoF values
|
|
||||||
float scale[6]; // 58 scale for delta DoF values
|
|
||||||
} mstudiobone_t;
|
|
||||||
typedef struct mstudiobonecontroller_t {
|
|
||||||
|
|
||||||
int bone; // -1 == 0
|
|
||||||
int type; // X, Y, Z, XR, YR, ZR, M
|
|
||||||
float start;
|
|
||||||
float end;
|
|
||||||
int rest; // byte index value at rest
|
|
||||||
int index; // 0-3 user set controller, 4 mouth
|
|
||||||
} mstudiobonecontroller_t;
|
|
||||||
typedef struct mstudiobbox_s {
|
|
||||||
int bone;
|
|
||||||
int group; // intersection group
|
|
||||||
vec3_t bbmin; // bounding box
|
|
||||||
vec3_t bbmax;
|
|
||||||
} mstudiobbox_t;
|
|
||||||
typedef struct mstudioseqgroup_s {
|
|
||||||
char label[32]; // textual name
|
|
||||||
char name[64]; // file name
|
|
||||||
cache_user_t cache; // cache index pointer
|
|
||||||
int data; // hack for group 0
|
|
||||||
} mstudioseqgroup_t;
|
|
||||||
typedef struct mstudioseqdesc_s {
|
|
||||||
char label[32]; // 00 sequence label
|
|
||||||
|
|
||||||
float fps; // 20 frames per second
|
|
||||||
int flags; // 24 looping/non-looping flags
|
|
||||||
|
|
||||||
int activity;
|
|
||||||
int actweight;
|
|
||||||
|
|
||||||
int numevents;
|
|
||||||
int eventindex;
|
|
||||||
|
|
||||||
int numframes; // 38 number of frames per sequence
|
|
||||||
|
|
||||||
int numpivots; // 3c number of foot pivots
|
|
||||||
int pivotindex;
|
|
||||||
|
|
||||||
int motiontype;
|
|
||||||
int motionbone;
|
|
||||||
vec3_t linearmovement; //4c
|
|
||||||
int automoveposindex; //58
|
|
||||||
int automoveangleindex;
|
|
||||||
|
|
||||||
vec3_t bbmin; // 60 per sequence bounding box
|
|
||||||
vec3_t bbmax; //6c
|
|
||||||
|
|
||||||
int numblends; //78
|
|
||||||
int animindex; // mstudioanim_t pointer relative to start of sequence group data
|
|
||||||
// [blend][bone][X, Y, Z, XR, YR, ZR]
|
|
||||||
|
|
||||||
int blendtype[2]; // X, Y, Z, XR, YR, ZR
|
|
||||||
float blendstart[2]; // starting value
|
|
||||||
float blendend[2]; // ending value
|
|
||||||
int blendparent;
|
|
||||||
|
|
||||||
int seqgroup; // sequence group for demand loading
|
|
||||||
|
|
||||||
int entrynode; // transition node at entry
|
|
||||||
int exitnode; // transition node at exit
|
|
||||||
int nodeflags; // transition rules
|
|
||||||
|
|
||||||
int nextseq; // auto advancing sequences
|
|
||||||
} mstudioseqdesc_t;
|
|
||||||
typedef struct mstudioevent_s {
|
|
||||||
int frame;
|
|
||||||
int event;
|
|
||||||
int type;
|
|
||||||
char options[64];
|
|
||||||
} mstudioevent_t;
|
|
||||||
typedef struct mstudiopivot_s {
|
|
||||||
vec3_t org; // pivot point
|
|
||||||
int start;
|
|
||||||
int end;
|
|
||||||
} mstudiopivot_t;
|
|
||||||
typedef struct mstudioattachment_s { //0x58
|
|
||||||
char name[32]; //00
|
|
||||||
int type; //20
|
|
||||||
int bone; //24
|
|
||||||
vec3_t org; // 28attachment point
|
|
||||||
vec3_t vectors[3]; //34
|
|
||||||
} mstudioattachment_t;
|
|
||||||
typedef struct mstudioanim_s {
|
|
||||||
unsigned short offset[6];
|
|
||||||
} mstudioanim_t;
|
|
||||||
typedef union mstudioanimvalue_s {
|
|
||||||
struct {
|
|
||||||
byte valid;
|
|
||||||
byte total;
|
|
||||||
} num;
|
|
||||||
short value;
|
|
||||||
} mstudioanimvalue_t;
|
|
||||||
|
|
||||||
|
|
||||||
//struct
|
|
||||||
typedef struct BlendingAPI_s {
|
|
||||||
|
|
||||||
int padding00;
|
|
||||||
void (*BoneSetup)(model_t *, float, int, vec3_t, vec3_t, byte *, byte *, int, edict_t *); //SV_StudioSetupBones
|
|
||||||
} BlendingAPI_t;
|
|
||||||
|
|
||||||
//globals
|
|
||||||
extern texture_t * global_r_notexture_mip;
|
|
||||||
|
|
||||||
// These are here because of SV_CheckBlendingInterface.
|
|
||||||
// SV_CheckBlendingInterface CLEARLY belongs in R.c, but it uses DLL
|
|
||||||
// functions, which are better off in their own file.
|
|
||||||
extern vec_t bonetransform[0x80][3][4];
|
|
||||||
extern vec_t rotationmatrix[3][4];
|
|
||||||
extern BlendingAPI_t * g_pSvBlendingAPI;
|
|
||||||
|
|
||||||
|
|
||||||
//functions
|
|
||||||
int SV_HitgroupForStudioHull(int index);
|
|
||||||
hull_t * SV_HullForStudioModel(edict_t * ent, vec3_t mins, vec3_t maxs, vec3_t arg_C, int * arg_10);
|
|
||||||
int R_GetStudioBounds(char * name, vec3_t mins, vec3_t maxs);
|
|
||||||
hull_t * R_StudioHull(model_t * arg_0, float arg_4, int arg_8, vec3_t arg_C, vec3_t arg_10, vec3_t arg_14, byte * arg_18, byte * arg_1C, int * OUT_arg_20_total, edict_t * OUT_arg_24, int arg_isCS);
|
|
||||||
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void GetAttachment(edict_t *, int, vec3_t, vec3_t);
|
|
||||||
HLDS_DLLEXPORT void GetBonePosition(edict_t*, int, vec3_t, vec3_t);
|
|
||||||
|
|
||||||
void R_InitTextures();
|
|
||||||
void R_ResetSvBlending();
|
|
||||||
#endif
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
#include "SV_chals.h"
|
|
||||||
#include "cmd.h"
|
|
||||||
#include "random.h"
|
|
||||||
#include "report.h"
|
|
||||||
#include "SV_mcast.h"
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
/*** STRUCTS ***/
|
|
||||||
typedef struct challenge_s {
|
|
||||||
|
|
||||||
netadr_t address;
|
|
||||||
int time;
|
|
||||||
int challenge;
|
|
||||||
} challenge_t;
|
|
||||||
|
|
||||||
|
|
||||||
/*** GLOBALS ***/
|
|
||||||
static challenge_t g_rg_sv_challenges[1024];
|
|
||||||
|
|
||||||
|
|
||||||
/*** FUNCTIONS ***/
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_CheckChallenge
|
|
||||||
// LOCATION: Master
|
|
||||||
// PATH: ConnectClient and rcon_validate
|
|
||||||
//
|
|
||||||
// UDP is easily spoofed. Challenge numbers make it a roughly
|
|
||||||
// 1 in 2 billion guessing attack, assuming our random selection is
|
|
||||||
// unpredictable. I remember this from the master; it's pretty easy.
|
|
||||||
*/
|
|
||||||
int SV_CheckChallenge(netadr_t * client, int challenge) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
if(client == NULL) { Sys_Error("SV_CheckChallenge: Null in arguments,\n"); return(0); }
|
|
||||||
|
|
||||||
if(NET_IsLocalAddress(*client)) { return 1; }
|
|
||||||
|
|
||||||
for(i = 0; i < 1023; i++) { //not how I prefer to do it actually.
|
|
||||||
|
|
||||||
if(NET_CompareBaseAdr(global_net_from, g_rg_sv_challenges[i].address) != 0) {
|
|
||||||
|
|
||||||
if(challenge == g_rg_sv_challenges[i].challenge) {
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// SV_RejectConnection(client, "Denied--bad challenge.\n");
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SV_RejectConnection(client, "Denied--no challenge for your address.\n");
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
void SVC_GetChallenge() {
|
|
||||||
|
|
||||||
#define OUT_GETCHALLENGE "\xff\xff\xff\xff" "A00000000 %u 2\n"
|
|
||||||
#define MAX_SIZEOF_OUTGC sizeof(OUT_GETCHALLENGE) + 9
|
|
||||||
//We write one integer, which can (and probably will) take up ten bytes.
|
|
||||||
//Ten - the two bytes taken up by %u == 8.
|
|
||||||
int i;
|
|
||||||
int oldest;
|
|
||||||
int oldestTime;
|
|
||||||
char packet[MAX_SIZEOF_OUTGC];
|
|
||||||
|
|
||||||
|
|
||||||
oldest = 0;
|
|
||||||
oldestTime = 0x7fffffff;
|
|
||||||
|
|
||||||
for(i = 0; i < 1024; i++) { //todo: hash index like in master3
|
|
||||||
if(NET_CompareBaseAdr(global_net_from, g_rg_sv_challenges[i].address) != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(g_rg_sv_challenges[i].time < oldestTime) {
|
|
||||||
oldestTime = g_rg_sv_challenges[i].time;
|
|
||||||
oldest = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i == 1024) { //no match, overwrite
|
|
||||||
|
|
||||||
g_rg_sv_challenges[oldest].challenge = (RandomLong(0, 0x7FFFFFFF) << 1) ^ RandomLong(0, 0x7FFFFFFF);
|
|
||||||
g_rg_sv_challenges[oldest].address = global_net_from;
|
|
||||||
g_rg_sv_challenges[oldest].time = global_realtime;
|
|
||||||
i = oldest;
|
|
||||||
}
|
|
||||||
else { //I'd like to create a new challenge number IF necessary.
|
|
||||||
|
|
||||||
if(g_rg_sv_challenges[oldest].time + 8 < global_realtime) {
|
|
||||||
|
|
||||||
g_rg_sv_challenges[oldest].challenge = (RandomLong(0, 0x7FFFFFFF) << 1) ^ RandomLong(0, 0x7FFFFFFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//gfUseLANAuthentication = 1;
|
|
||||||
|
|
||||||
//Here we tell the client what authentication protocol to use.
|
|
||||||
//Well right now we only have one--hashed CD keys.
|
|
||||||
|
|
||||||
//reuse i as the size.
|
|
||||||
i = sprintf(packet, OUT_GETCHALLENGE, g_rg_sv_challenges[i].challenge) + 1;
|
|
||||||
NET_SendPacket(NS_SERVER, i, packet, global_net_from);
|
|
||||||
}
|
|
||||||
void SVC_ServiceChallenge() {
|
|
||||||
|
|
||||||
#define OUT_CHALLENGE "\xff\xff\xff\xff" "challenge rcon %u\n"
|
|
||||||
#define MAX_SIZEOF_CH sizeof(OUT_CHALLENGE) + 8
|
|
||||||
|
|
||||||
int i;
|
|
||||||
int oldest;
|
|
||||||
int oldestTime;
|
|
||||||
char packet[MAX_SIZEOF_CH];
|
|
||||||
|
|
||||||
|
|
||||||
if(Cmd_Argc() != 2 || Q_strcasecmp(Cmd_Argv(1), "rcon") != 0) { return; }
|
|
||||||
|
|
||||||
oldest = 0;
|
|
||||||
oldestTime = 0x7fffffff;
|
|
||||||
for(i = 0; i < 1024; i++) { //todo: hash table like in master3
|
|
||||||
if(NET_CompareBaseAdr(global_net_from, g_rg_sv_challenges[i].address) != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(g_rg_sv_challenges[i].time < oldestTime) {
|
|
||||||
oldestTime = g_rg_sv_challenges[i].time;
|
|
||||||
oldest = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i == 1024) {
|
|
||||||
|
|
||||||
g_rg_sv_challenges[oldest].challenge = (RandomLong(0, 0x7FFFFFFF) << 1) ^ RandomLong(0, 0x7FFFFFFF);
|
|
||||||
g_rg_sv_challenges[oldest].address = global_net_from;
|
|
||||||
g_rg_sv_challenges[oldest].time = global_realtime;
|
|
||||||
i = oldest;
|
|
||||||
}
|
|
||||||
else if(g_rg_sv_challenges[oldest].time + 8 < global_realtime) {
|
|
||||||
|
|
||||||
g_rg_sv_challenges[oldest].challenge = (RandomLong(0, 0x7FFFFFFF) << 1) ^ RandomLong(0, 0x7FFFFFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
i = sprintf(packet, OUT_CHALLENGE, g_rg_sv_challenges[i].challenge) + 1;
|
|
||||||
NET_SendPacket(NS_SERVER, i, packet, global_net_from);
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/* Just a few functions I could siphon away to somewhere else.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_CHALLENGE_HEADER
|
|
||||||
#define OSHLDS_SV_CHALLENGE_HEADER
|
|
||||||
|
|
||||||
#include "NET.h"
|
|
||||||
|
|
||||||
int SV_CheckChallenge(netadr_t *, int);
|
|
||||||
void SVC_GetChallenge();
|
|
||||||
void SVC_ServiceChallenge();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,28 +0,0 @@
|
|||||||
/* Resource lists, and the like.
|
|
||||||
// Couldn't really get a great name in eight letters.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_CLRES_HEADER
|
|
||||||
#define OSHLDS_SV_CLRES_HEADER
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "NET.h"
|
|
||||||
|
|
||||||
//functions
|
|
||||||
int COM_CreateCustomization(customization_t *, resource_t *, int, int, customization_t **, int *);
|
|
||||||
void COM_ClearCustomizationList(customization_t *);
|
|
||||||
|
|
||||||
void SV_CreateResourceList();
|
|
||||||
void SV_CreateGenericResources();
|
|
||||||
void SV_RequestMissingResourcesFromClients();
|
|
||||||
void SV_ClearResourceLists(client_t *);
|
|
||||||
void SV_MoveToOnHandList(resource_t *);
|
|
||||||
void SV_ParseResourceList();
|
|
||||||
|
|
||||||
int SV_TransferConsistencyInfo();
|
|
||||||
void SV_ParseConsistencyResponse();
|
|
||||||
void SV_SendResources(sizebuf_t *);
|
|
||||||
|
|
||||||
void SV_CL_RES_Init();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,277 +0,0 @@
|
|||||||
#include "SV_frame.h"
|
|
||||||
|
|
||||||
#include "host.h"
|
|
||||||
#include "master.h"
|
|
||||||
#include "Modding.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "SV_clres.h"
|
|
||||||
#include "SV_mcast.h"
|
|
||||||
#include "SV_pkt.h"
|
|
||||||
#include "SV_pktcl.h"
|
|
||||||
#include "SV_phys.h"
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
/*** GLOBALS ***/
|
|
||||||
|
|
||||||
static cvar_t cvar_sv_timeout = { "sv_timeout", "60", FCVAR_NONE, 60.0, NULL };
|
|
||||||
cvar_t cvar_clockwindow = { "clockwindow", "0.5", FCVAR_NONE, 0.5, NULL }; //used in NET.c as well, but it's in the init so I'm okay with that.
|
|
||||||
|
|
||||||
|
|
||||||
/*** FUNCTIONS ***/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//checks and balances
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_CheckTimeouts
|
|
||||||
// PATH: SV_Frame
|
|
||||||
//
|
|
||||||
// If a client's been doing nothing for a prolonged period of time, we
|
|
||||||
// boot them to make room for someone a little more active.
|
|
||||||
*/
|
|
||||||
void SV_CheckTimeouts() {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
double CutoffValue;
|
|
||||||
client_t * ptrClient;
|
|
||||||
|
|
||||||
|
|
||||||
CutoffValue = global_realtime - cvar_sv_timeout.value;
|
|
||||||
for(ptrClient = global_svs.clients, i = 0; i < global_svs.allocated_client_slots; i++, ptrClient++) {
|
|
||||||
|
|
||||||
if((ptrClient->padding00_used == 0 && ptrClient->padding0C_connected == 0 && ptrClient->padding04 == 0) ||
|
|
||||||
(ptrClient->padding2438_IsFakeClient != 0)) { continue; }
|
|
||||||
|
|
||||||
if(ptrClient->netchan1C.last_received < CutoffValue) {
|
|
||||||
|
|
||||||
SV_BroadcastPrintf("%s timed out\n", ptrClient->PlayerName);
|
|
||||||
SV_DropClient(ptrClient, 0, "Timed out.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_CheckMapDifferences
|
|
||||||
// PATH: SV_Frame
|
|
||||||
//
|
|
||||||
// Every five seconds, this loops through all of our clients and...
|
|
||||||
// well, I'm not actually sure. Apparently it compares the CRCs of the maps.
|
|
||||||
// But why would they change in between connect and shutdown?
|
|
||||||
*/
|
|
||||||
void SV_CheckMapDifferences() {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
client_t * ptrClient;
|
|
||||||
static double lastcheck = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if(global_realtime - lastcheck < 5) { return; }
|
|
||||||
lastcheck = global_realtime;
|
|
||||||
|
|
||||||
|
|
||||||
for(ptrClient = global_svs.clients, i = 0; i < global_svs.allocated_client_slots; i++, ptrClient++) {
|
|
||||||
|
|
||||||
if(ptrClient->padding00_used == 0 || ptrClient->local_map_CRC == 0 || ptrClient->netchan1C.remote_address.type == NA_LOOPBACK) { continue; }
|
|
||||||
if(global_sv.map_CRC != ptrClient->local_map_CRC) {
|
|
||||||
ptrClient->netchan1C.netchan_message.overflow |= 2; //I'm not sure why we do this.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_CheckCmdTimes
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_Frame
|
|
||||||
//
|
|
||||||
// Manipulates a few variables in the client structures. There are so many
|
|
||||||
// damnable counters, it's gonna take a miracle to sort them all out.
|
|
||||||
// Based on the function name, I'd say these ones have to do with commands...
|
|
||||||
*/
|
|
||||||
void SV_CheckCmdTimes() {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
client_t * ptrClient;
|
|
||||||
double varc;
|
|
||||||
float ClockWindowVar;
|
|
||||||
static double lastreset = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if(1.0 > global_realtime - lastreset) { return; }
|
|
||||||
|
|
||||||
lastreset = global_realtime;
|
|
||||||
for(i = 0; i < global_svs.allocated_client_slots; i++) { //It's more optimized in ASM to increment the pointer BTW
|
|
||||||
|
|
||||||
ptrClient = &(global_svs.clients[i]);
|
|
||||||
if(ptrClient->padding0C_connected == 0 || ptrClient->padding00_used == 0) { continue; }
|
|
||||||
if(ptrClient->padding2474_LastCommandTime == 0) {
|
|
||||||
ptrClient->padding2474_LastCommandTime = global_realtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
varc = ptrClient->padding247C_LastRunTime + ptrClient->padding2474_LastCommandTime - global_realtime;
|
|
||||||
ClockWindowVar = cvar_clockwindow.value;
|
|
||||||
if(varc > ClockWindowVar) {
|
|
||||||
|
|
||||||
ptrClient->padding2484_NextRunTime = ClockWindowVar + global_realtime;
|
|
||||||
ptrClient->padding247C_LastRunTime = global_realtime - ptrClient->padding2474_LastCommandTime;
|
|
||||||
}
|
|
||||||
else if(varc < -ClockWindowVar) {
|
|
||||||
|
|
||||||
ptrClient->padding247C_LastRunTime = global_realtime - ptrClient->padding2474_LastCommandTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_IsSimulating
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_Frame
|
|
||||||
//
|
|
||||||
// Returns 1. I'm guessing 'isSimulating' means 'isRunningAMultiplayerServer',
|
|
||||||
// or something to that effect, but I'm not really interested in mapping it all out.
|
|
||||||
*/
|
|
||||||
int SV_IsSimulating() {
|
|
||||||
|
|
||||||
//The ordering is funky. Cound be important though.
|
|
||||||
|
|
||||||
/* This kind've indicates there's more to it, but for a dedicated server,
|
|
||||||
// I think we're always 'simulating'.
|
|
||||||
if(global_sv.padding04 != 0) { return(0); }
|
|
||||||
if(global_svs.maxclients > 1) { return(1); }
|
|
||||||
if(*key_dest != 0) { return(0); }
|
|
||||||
if(global_cls.state == ca_dedicated || global_cls.state == ca_active) { return(1); }
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
*/
|
|
||||||
if(global_sv.padding04 != 0) { return(0); }
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_GatherStatistics
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_Frame
|
|
||||||
//
|
|
||||||
// Adds subtracts and multiplies its way to victory. So what if we don't
|
|
||||||
// actually know what it's tracking...
|
|
||||||
*/
|
|
||||||
void SV_GatherStatistics() {
|
|
||||||
|
|
||||||
unsigned int i, var_10;
|
|
||||||
float var_14;
|
|
||||||
client_t * client;
|
|
||||||
|
|
||||||
if(global_realtime < global_svs.padding38) {
|
|
||||||
|
|
||||||
SV_CountPlayers(&i);
|
|
||||||
global_svs.padding38 = 3600 + global_realtime;
|
|
||||||
|
|
||||||
global_svs.padding48 = 0;
|
|
||||||
global_svs.padding4C = 0;
|
|
||||||
global_svs.padding50 = 0;
|
|
||||||
global_svs.padding54 = 0;
|
|
||||||
global_svs.padding58 = 0;
|
|
||||||
global_svs.padding5C = i;
|
|
||||||
global_svs.padding60 = i;
|
|
||||||
global_svs.padding64 = 0;
|
|
||||||
global_svs.padding68 = 0;
|
|
||||||
global_svs.padding6C = 0;
|
|
||||||
global_svs.padding70 = 0;
|
|
||||||
global_svs.padding74 = 0;
|
|
||||||
global_svs.padding78 = 0;
|
|
||||||
global_svs.padding7C = 0;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(global_realtime > global_svs.padding40) { return; }
|
|
||||||
|
|
||||||
global_svs.padding48++;
|
|
||||||
global_svs.padding40 = 60 + global_realtime;
|
|
||||||
SV_CountPlayers(&i);
|
|
||||||
|
|
||||||
global_svs.padding64 += (i * 100) / global_svs.allocated_client_slots;
|
|
||||||
if(global_svs.padding48 > 0) { //doesn't look possible
|
|
||||||
|
|
||||||
global_svs.padding68 = global_svs.padding64 / global_svs.padding48;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i < global_svs.padding5C) {
|
|
||||||
global_svs.padding5C = i;
|
|
||||||
}
|
|
||||||
else if(i > global_svs.padding60) {
|
|
||||||
global_svs.padding60 = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i >= global_svs.allocated_client_slots - 1) {
|
|
||||||
global_svs.padding4C++;
|
|
||||||
}
|
|
||||||
if(i <= 1) {
|
|
||||||
global_svs.padding50++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(global_svs.padding48 > 0) {
|
|
||||||
|
|
||||||
global_svs.padding54 = (global_svs.padding4C * 100) / global_svs.padding48;
|
|
||||||
global_svs.padding58 = (global_svs.padding50 * 100) / global_svs.padding48;
|
|
||||||
}
|
|
||||||
|
|
||||||
//i is now a free temp variable.
|
|
||||||
var_14 = 0;
|
|
||||||
var_10 = 0;
|
|
||||||
for(i = 0, client = global_svs.clients; i < global_svs.allocated_client_slots; i++, client++) {
|
|
||||||
|
|
||||||
if(client->padding00_used == 0 || client->padding2438_IsFakeClient != 0) { continue; }
|
|
||||||
|
|
||||||
var_10++;
|
|
||||||
var_14 += client->ping;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var_10 > 1) {
|
|
||||||
var_14 = var_14 / var_10; //average ping;
|
|
||||||
}
|
|
||||||
|
|
||||||
global_svs.padding78 += var_14;
|
|
||||||
if(global_svs.padding48 > 0) {
|
|
||||||
|
|
||||||
global_svs.padding7C = global_svs.padding78 / global_svs.padding48;
|
|
||||||
}
|
|
||||||
|
|
||||||
global_svs.padding74 = global_svs.padding70 / global_svs.padding6C;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SV_Frame() {
|
|
||||||
|
|
||||||
if(global_sv.active == 0) { return; }
|
|
||||||
|
|
||||||
gGlobalVariables.frametime = host_frametime;
|
|
||||||
global_sv.time14 = global_sv.time0c;
|
|
||||||
|
|
||||||
SV_CheckCmdTimes();
|
|
||||||
SV_ReadPackets();
|
|
||||||
if(SV_IsSimulating()) { SV_Physics(); }
|
|
||||||
|
|
||||||
global_sv.time0c += host_frametime;
|
|
||||||
|
|
||||||
SV_QueryMovevarsChanged();
|
|
||||||
SV_RequestMissingResourcesFromClients();
|
|
||||||
|
|
||||||
// if(Steam) don't do this. hehe.
|
|
||||||
//WON_HandleServerAuthMsgs();
|
|
||||||
|
|
||||||
// ValveAuth_Init(); This function would be a lot more interestign if I still cared about the auth server.
|
|
||||||
Master_Heartbeat();
|
|
||||||
SV_CheckTimeouts();
|
|
||||||
//SV_SecurityUpdate();
|
|
||||||
SV_SendClientMessages();
|
|
||||||
SV_CheckMapDifferences();
|
|
||||||
SV_GatherStatistics();
|
|
||||||
//SV_ProcessSteamClientConnections(); //I've a feeling we can skip this...
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_Frame_Init
|
|
||||||
// PATH: SV_Init
|
|
||||||
//
|
|
||||||
// Place those cvars where they need to go.
|
|
||||||
*/
|
|
||||||
void SV_Frame_Init() {
|
|
||||||
|
|
||||||
Cvar_RegisterVariable(&cvar_clockwindow);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
/* This is where I'm throwing frame things, which probably will include packet
|
|
||||||
// pathways. Bridge between host and more secific areas then.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_FRAME_HEADER
|
|
||||||
#define OSHLDS_SV_FRAME_HEADER
|
|
||||||
|
|
||||||
void SV_Frame();
|
|
||||||
void SV_Frame_Init();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,310 +0,0 @@
|
|||||||
/* The SV_ functions are pretty much a good chunk of code, divided into
|
|
||||||
// separate segments that can't be easily distinguished by name. They use many
|
|
||||||
// global variables and will often build onto each other in a very heirarchial
|
|
||||||
// manner. Most of them handle structs which, unfortunately, are very very
|
|
||||||
// different from what's in QW. Piecing together the structs alone has taken
|
|
||||||
// a lot of the time.
|
|
||||||
//
|
|
||||||
// Slowly but surely, I'm taking chunks of related SV functions and dumping
|
|
||||||
// them into their own file. This one is STILL chaotic though.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_HEADER
|
|
||||||
#define OSHLDS_SV_HEADER
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "pm.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_PHYSENTS 600
|
|
||||||
#define MAX_MOVEENTS 64
|
|
||||||
#define MAX_PHYSINFO_STRING 256
|
|
||||||
|
|
||||||
#define EF_BRIGHTFIELD 0x01 // swirling cloud of particles
|
|
||||||
#define EF_MUZZLEFLASH 0x02 // single frame ELIGHT on entity attachment 0
|
|
||||||
#define EF_BRIGHTLIGHT 0x04 // DLIGHT centered at entity origin
|
|
||||||
#define EF_DIMLIGHT 0x08 // player flashlight
|
|
||||||
#define EF_INVLIGHT 0x10 // get lighting from ceiling
|
|
||||||
#define EF_NOINTERP 0x20 // don't interpolate the next frame
|
|
||||||
#define EF_LIGHT 0x40 // rocket flare glow sprite
|
|
||||||
#define EF_NODRAW 0x80 // don't draw entity
|
|
||||||
//structs
|
|
||||||
/*
|
|
||||||
typedef struct clearpacketentities3_s { //0x154 I think
|
|
||||||
|
|
||||||
char padding1[0x154];
|
|
||||||
} clearpacketentities3_t;
|
|
||||||
typedef struct clearpacketentities2_s {
|
|
||||||
|
|
||||||
uint32 padding00; //a counter probably
|
|
||||||
uint32 padding04;
|
|
||||||
uint32 padding08;
|
|
||||||
uint32 padding0C;
|
|
||||||
uint32 padding10;
|
|
||||||
uint32 padding14;
|
|
||||||
uint32 padding18;
|
|
||||||
uint32 padding1C;
|
|
||||||
uint32 padding20;
|
|
||||||
clearpacketentities3_t * padding24;
|
|
||||||
uint32 padding28;
|
|
||||||
uint32 padding2C;
|
|
||||||
} clearpacketentities2_t;
|
|
||||||
typedef struct clearpacketentities_s {
|
|
||||||
|
|
||||||
uint32 padding00;
|
|
||||||
uint32 padding04;
|
|
||||||
uint32 padding08;
|
|
||||||
uint32 padding0C;
|
|
||||||
char padding1[0x17D0];
|
|
||||||
uint32 padding17E0;
|
|
||||||
uint32 padding17E4;
|
|
||||||
clearpacketentities2_t * padding17E8;
|
|
||||||
uint32 padding17EC;
|
|
||||||
} clearpacketentities_t;
|
|
||||||
*/
|
|
||||||
typedef struct filteredip_s {
|
|
||||||
struct filteredip_s *next;
|
|
||||||
netadr_t adr;
|
|
||||||
netadr_t adrmask;
|
|
||||||
} filteredip_t;
|
|
||||||
typedef struct KeyValueData_s { //SDK
|
|
||||||
char *szClassName; // in: entity classname
|
|
||||||
char *szKeyName; // in: name of key
|
|
||||||
char *szValue; // in: value of key
|
|
||||||
long fHandled; // out: DLL sets to true if key-value pair was understood
|
|
||||||
} KeyValueData_t;
|
|
||||||
typedef struct physent_s { //e0
|
|
||||||
|
|
||||||
char name[32]; // 00 Name of model, or "player" or "world".
|
|
||||||
int player; //20
|
|
||||||
vec3_t origin; // 24 Model's origin in world coordinates.
|
|
||||||
struct model_s *model; // 30 only for bsp models
|
|
||||||
struct model_s *studiomodel; // 34 SOLID_BBOX, but studio clip intersections.
|
|
||||||
vec3_t mins, maxs; // 38 44 only for non-bsp models
|
|
||||||
int info; // 50 For client or server to use to identify (index into edicts or cl_entities)
|
|
||||||
vec3_t angles; // 54 rotated entities need this info for hull testing to work.
|
|
||||||
|
|
||||||
int solid; // 60 Triggers and func_door type WATER brushes are SOLID_NOT
|
|
||||||
int skin; // BSP Contents for such things like fun_door water brushes.
|
|
||||||
int rendermode; // So we can ignore glass
|
|
||||||
|
|
||||||
// Complex collision detection.
|
|
||||||
float frame;
|
|
||||||
int sequence; //70
|
|
||||||
byte controller[4]; //74
|
|
||||||
byte blending[2]; //78
|
|
||||||
|
|
||||||
int movetype; //7c
|
|
||||||
int takedamage;
|
|
||||||
int blooddecal;
|
|
||||||
int team;
|
|
||||||
int classnumber; //8c
|
|
||||||
|
|
||||||
// For mods
|
|
||||||
int iuser1;
|
|
||||||
int iuser2;
|
|
||||||
int iuser3;
|
|
||||||
int iuser4; //9c
|
|
||||||
float fuser1;
|
|
||||||
float fuser2;
|
|
||||||
float fuser3;
|
|
||||||
float fuser4; //ac
|
|
||||||
vec3_t vuser1; //b0
|
|
||||||
vec3_t vuser2; //bc
|
|
||||||
vec3_t vuser3; //c8
|
|
||||||
vec3_t vuser4; //d4
|
|
||||||
} physent_t;
|
|
||||||
typedef struct playermove_s { //SDK, different than in QW. 0x4F5CC bytes. That's a lot.
|
|
||||||
|
|
||||||
int player_index; // 00 So we don't try to run the PM_CheckStuck nudging too quickly.
|
|
||||||
qboolean server; // 04 For debugging, are we running physics code on server side?
|
|
||||||
|
|
||||||
qboolean multiplayer; // 08 1 == multiplayer server
|
|
||||||
float time; // 0c global_realtime on host, for reckoning duck timing
|
|
||||||
float frametime; // 10 Duration of this frame
|
|
||||||
|
|
||||||
vec3_t forward, right, up; // 14 20 2c// Vectors for angles
|
|
||||||
// player state
|
|
||||||
vec3_t origin; // 38 Movement origin.
|
|
||||||
vec3_t angles; // 44 Movement view angles.
|
|
||||||
vec3_t oldangles; // 50 Angles before movement view angles were looked at.
|
|
||||||
vec3_t velocity; // 5c Current movement direction.
|
|
||||||
vec3_t movedir; // 68 For waterjumping, a forced forward velocity so we can fly over lip of ledge.
|
|
||||||
vec3_t basevelocity; // 74 Velocity of the conveyor we are standing, e.g.
|
|
||||||
|
|
||||||
// For ducking/dead
|
|
||||||
vec3_t view_ofs; // 80 Our eye position.
|
|
||||||
float flDuckTime; // 8c Time we started duck
|
|
||||||
qboolean bInDuck; // 90 In process of ducking or ducked already?
|
|
||||||
|
|
||||||
// For walking/falling
|
|
||||||
int flTimeStepSound; // Next time we can play a step sound
|
|
||||||
int iStepLeft;
|
|
||||||
|
|
||||||
float flFallVelocity; // 9c
|
|
||||||
vec3_t punchangle; // a0
|
|
||||||
|
|
||||||
float flSwimTime; // ac
|
|
||||||
|
|
||||||
float flNextPrimaryAttack;
|
|
||||||
|
|
||||||
int effects; // b4 MUZZLE FLASH, e.g.
|
|
||||||
|
|
||||||
int flags; // b8 FL_ONGROUND, FL_DUCKING, etc.
|
|
||||||
int usehull; // bc 0 = regular player hull, 1 = ducked player hull, 2 = point hull
|
|
||||||
float gravity; // c0 Our current gravity and friction.
|
|
||||||
float friction;
|
|
||||||
int oldbuttons; // c8 Buttons last usercmd
|
|
||||||
float waterjumptime; // Amount of time left in jumping out of water cycle.
|
|
||||||
qboolean dead; // d0 Are we a dead player?
|
|
||||||
int deadflag;
|
|
||||||
int spectator; // d8 Should we use spectator physics model?
|
|
||||||
int movetype; // Our movement type, NOCLIP, WALK, FLY. Form of: MOVETYPE_WALK (sdk)
|
|
||||||
|
|
||||||
int onground; // e0 In an attempt to debug Windows DLLs, this struct was checked and it is confirmed on Windows
|
|
||||||
int waterlevel;
|
|
||||||
int watertype;
|
|
||||||
int oldwaterlevel;
|
|
||||||
|
|
||||||
char sztexturename[256]; //f0
|
|
||||||
char chtexturetype; //1f0
|
|
||||||
|
|
||||||
float maxspeed;
|
|
||||||
float clientmaxspeed; //1f8 Player specific maxspeed
|
|
||||||
|
|
||||||
// For mods
|
|
||||||
int iuser1;
|
|
||||||
int iuser2; //200
|
|
||||||
int iuser3;
|
|
||||||
int iuser4;
|
|
||||||
float fuser1;
|
|
||||||
float fuser2; //210
|
|
||||||
float fuser3;
|
|
||||||
float fuser4;
|
|
||||||
vec3_t vuser1; //21c
|
|
||||||
vec3_t vuser2; //228
|
|
||||||
vec3_t vuser3; //234
|
|
||||||
vec3_t vuser4; //240
|
|
||||||
// world state
|
|
||||||
// Number of entities to clip against.
|
|
||||||
int numphysent; //24c
|
|
||||||
physent_t physents[MAX_PHYSENTS]; //250 +20D00?
|
|
||||||
// Number of momvement entities (ladders)
|
|
||||||
int nummoveent; //20f50
|
|
||||||
// just a list of ladders
|
|
||||||
physent_t moveents[MAX_MOVEENTS]; //20f54 + 3800
|
|
||||||
|
|
||||||
// All things being rendered, for tracing against things you don't actually collide with
|
|
||||||
int numvisent; //24754
|
|
||||||
physent_t visents[MAX_PHYSENTS]; //24758
|
|
||||||
|
|
||||||
// input to run through physics.
|
|
||||||
usercmd_t cmd; //45458
|
|
||||||
|
|
||||||
// Trace results for objects we collided with.
|
|
||||||
int numtouch; //4548c matches SDK
|
|
||||||
pmtrace_t touchindex[MAX_PHYSENTS]; //45490 + 9F60
|
|
||||||
|
|
||||||
char physinfo[ MAX_PHYSINFO_STRING ]; // 4F3F0 Physics info string
|
|
||||||
|
|
||||||
struct movevars_s * movevars; //4F4F0
|
|
||||||
vec3_t player_mins[4]; //4F4F4
|
|
||||||
vec3_t player_maxs[4]; //4f524
|
|
||||||
|
|
||||||
// Common functions
|
|
||||||
HLDS_DLLEXPORT const char * (*PM_Info_ValueForKey)(const char *s, const char *key);
|
|
||||||
HLDS_DLLEXPORT void (*PM_Particle)(vec3_t origin, int color, float life, int zpos, int zvel);
|
|
||||||
HLDS_DLLEXPORT int (*PM_TestPlayerPosition) (vec3_t pos, pmtrace_t *ptrace);
|
|
||||||
HLDS_DLLEXPORT void (*Con_NPrintf)(int idx, const char *fmt, ...);
|
|
||||||
HLDS_DLLEXPORT void (*Con_DPrintf)(const char *fmt, ...);
|
|
||||||
HLDS_DLLEXPORT void (*Con_Printf)(const char *fmt, ...);
|
|
||||||
HLDS_DLLEXPORT double (*Sys_FloatTime)(void);
|
|
||||||
HLDS_DLLEXPORT void (*PM_StuckTouch)(int hitent, pmtrace_t *ptraceresult);
|
|
||||||
HLDS_DLLEXPORT int (*PM_PointContents)(vec3_t p, int *truecontents);
|
|
||||||
HLDS_DLLEXPORT int (*PM_TruePointContents)(vec3_t p);
|
|
||||||
HLDS_DLLEXPORT int (*PM_HullPointContents)(struct hull_s *hull, int num, vec3_t p);
|
|
||||||
HLDS_DLLEXPORT pmtrace_t (*PM_PlayerTrace)(vec3_t start, vec3_t end, int traceFlags, int ignore_pe);
|
|
||||||
HLDS_DLLEXPORT pmtrace_t * (*PM_TraceLine)(vec3_t start, vec3_t end, int flags, int usehull, int ignore_pe);
|
|
||||||
HLDS_DLLEXPORT long (*RandomLong)(long lLow, long lHigh);
|
|
||||||
HLDS_DLLEXPORT float (*RandomFloat)(float flLow, float flHigh);
|
|
||||||
HLDS_DLLEXPORT int (*PM_GetModelType)(struct model_s *mod);
|
|
||||||
HLDS_DLLEXPORT void (*PM_GetModelBounds)(struct model_s *mod, vec3_t mins, vec3_t maxs);
|
|
||||||
HLDS_DLLEXPORT hull_t * (*PM_HullForBsp)(physent_t *pe, vec3_t offset);
|
|
||||||
HLDS_DLLEXPORT float (*PM_TraceModel)(physent_t *pEnt, vec3_t start, vec3_t end, trace_t *trace);
|
|
||||||
HLDS_DLLEXPORT int (*COM_FileSize)(char *filename);
|
|
||||||
HLDS_DLLEXPORT byte * (*COM_LoadFile)(const char *path, int usehunk, int *pLength);
|
|
||||||
HLDS_DLLEXPORT void (*COM_FreeFile)(byte *buffer);
|
|
||||||
HLDS_DLLEXPORT char * (*memfgets)(byte *pMemFile, int fileSize, int *pFilePos, char *pBuffer, int bufferSize);
|
|
||||||
|
|
||||||
// Functions
|
|
||||||
// Run functions for this frame?
|
|
||||||
HLDS_DLLEXPORT qboolean runfuncs;
|
|
||||||
HLDS_DLLEXPORT void (*PM_PlaySound)(int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch);
|
|
||||||
HLDS_DLLEXPORT const char * (*PM_TraceTexture)(int ground, vec3_t vstart, vec3_t vend);
|
|
||||||
HLDS_DLLEXPORT void (*PM_PlaybackEventFull)(int flags, int clientindex, unsigned short eventindex, float delay, vec3_t origin, vec3_t angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT pmtrace_t (*PM_PlayerTraceEx)(vec3_t start, vec3_t end, int traceFlags, int (*pfnIgnore)(physent_t *pe));
|
|
||||||
HLDS_DLLEXPORT int (*PM_TestPlayerPositionEx)(vec3_t pos, pmtrace_t *ptrace, int (*pfnIgnore)(physent_t *pe));
|
|
||||||
HLDS_DLLEXPORT pmtrace_t * (*PM_TraceLineEx)(vec3_t start, vec3_t end, int flags, int usehull, int (*pfnIgnore)(physent_t *pe));
|
|
||||||
} playermove_t;
|
|
||||||
typedef struct gpnewusermsg_struct_s { //unknown
|
|
||||||
|
|
||||||
int32 padding00_id; //not larger than 1 byte
|
|
||||||
int32 padding04_size; // ""
|
|
||||||
union { //This is just plain evil.
|
|
||||||
int32 asInts[4];
|
|
||||||
char asString[16];
|
|
||||||
} padding08_name;
|
|
||||||
struct gpnewusermsg_struct_s * next; //18
|
|
||||||
int32 padding1C; // Never seen referenced.
|
|
||||||
} gpnewusermsg_struct_t;
|
|
||||||
|
|
||||||
|
|
||||||
//vars
|
|
||||||
|
|
||||||
extern playermove_t * global_pmove;
|
|
||||||
extern playermove_t global_svmove;
|
|
||||||
extern edict_t * global_sv_player;
|
|
||||||
extern gpnewusermsg_struct_t * global_sv_gpNewUserMsg;
|
|
||||||
extern gpnewusermsg_struct_t * global_sv_gpUserMsg;
|
|
||||||
|
|
||||||
extern char global_localinfo[0x8001];
|
|
||||||
extern int key_dest; //Unclear purpose
|
|
||||||
|
|
||||||
|
|
||||||
//Functions
|
|
||||||
void SV_Init();
|
|
||||||
void SV_CountPlayers(int *);
|
|
||||||
void SV_InvokeCallback();
|
|
||||||
void SV_SetCallback(uint32, uint32, uint32, uint32 *, uint32, uint32);
|
|
||||||
void SV_SetNewInfo(uint32);
|
|
||||||
void SV_SetMaxclients();
|
|
||||||
void SV_ServerShutdown();
|
|
||||||
void SV_GetPlayerHulls();
|
|
||||||
int SV_ModelIndex(char *);
|
|
||||||
void SV_InactivateClients();
|
|
||||||
int SV_SpawnServer(int, const char *, const char *);
|
|
||||||
|
|
||||||
void SV_ActivateServer(int);
|
|
||||||
|
|
||||||
void SV_LoadEntities();
|
|
||||||
void SV_AllocPacketEntities(client_frame_t *, int);
|
|
||||||
void SV_DeallocateDynamicData();
|
|
||||||
|
|
||||||
|
|
||||||
void SV_ClearCaches();
|
|
||||||
void Host_ClearClients();
|
|
||||||
void SV_ClearClientStates();
|
|
||||||
void SV_ClearEntities();
|
|
||||||
void SV_ClearFrames(client_frame_t **);
|
|
||||||
void SV_ClearPacketEntities(client_frame_t *);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT unsigned char * SV_FatPVS(vec3_t);
|
|
||||||
HLDS_DLLEXPORT unsigned char * SV_FatPAS(vec3_t);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT edict_t * PF_CreateFakeClient_I(const char *);
|
|
||||||
HLDS_DLLEXPORT const char * PM_SV_TraceTexture(int, vec3_t, vec3_t);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,860 +0,0 @@
|
|||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#include "SV_mcast.h"
|
|
||||||
#include "common.h"
|
|
||||||
#include "cmd.h"
|
|
||||||
#include "Modding.h"
|
|
||||||
#include "report.h"
|
|
||||||
#include "SV_clres.h"
|
|
||||||
#include "sys.h"
|
|
||||||
#include "world.h"
|
|
||||||
|
|
||||||
//SV_ValidClientMulticast: Bad argument 132
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_PointLeafnum
|
|
||||||
// LOCATION: by name, gl_q2bsp.c, but the 'point' functions are spread out.
|
|
||||||
// PATH: SV_Multicast, SV_ValidClientMulticast, EV_Playback
|
|
||||||
//
|
|
||||||
// Finds the index of a leaf, relative to the worldmodel leaves. Or, in other
|
|
||||||
// words, we're solving for i: our leaf == sv.worldmodel->leafs[i]
|
|
||||||
*/
|
|
||||||
int SV_PointLeafnum(vec3_t vector) {
|
|
||||||
|
|
||||||
mleaf_t * leaf;
|
|
||||||
|
|
||||||
|
|
||||||
leaf = Mod_PointInLeaf(vector, global_sv.worldmodel);
|
|
||||||
if(leaf == NULL) { return(0); }
|
|
||||||
|
|
||||||
return(leaf - global_sv.worldmodel->leafs);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_ValidClientMulticast
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_Multicast, EV_Playback
|
|
||||||
//
|
|
||||||
// We send and send and send and send and send send send send send send send
|
|
||||||
*/
|
|
||||||
int SV_ValidClientMulticast(client_t * cl, int leafnum, int arg_8) {
|
|
||||||
|
|
||||||
byte * row;
|
|
||||||
int index;
|
|
||||||
//We aren't a singleplayer game, so I can't just return 1 and be done...
|
|
||||||
|
|
||||||
if(cl->padding243C_proxy != 0) { return(1); }
|
|
||||||
|
|
||||||
|
|
||||||
arg_8 &= 0x7f;
|
|
||||||
switch(arg_8) {
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
return(1);
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
row = CM_LeafPVS(leafnum);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
row = CM_LeafPAS(leafnum);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
Con_Printf("%s: Bad argument %i", __FUNCTION__, arg_8);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(row == NULL) { return(1); }
|
|
||||||
|
|
||||||
index = ((SV_PointLeafnum(cl->padding4A84->v.origin) - 1));
|
|
||||||
//We are checking the var_Cth bit. I know it's messy, but that's all we're doing.
|
|
||||||
if((((row[index / 8]) >> (index & 7)) & 1) != 0) { return(1); }
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_Multicast
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_StartSound, PF_MessageEnd_I
|
|
||||||
//
|
|
||||||
// Just does some bit checking. How odd.
|
|
||||||
*/
|
|
||||||
void SV_Multicast(edict_t * ent, vec3_t origin, int arg_8_flags, int arg_c_bool) {
|
|
||||||
|
|
||||||
int leafnum;
|
|
||||||
unsigned int i;
|
|
||||||
client_t * oldclient, * client;
|
|
||||||
|
|
||||||
|
|
||||||
oldclient = global_host_client;
|
|
||||||
leafnum = SV_PointLeafnum(origin);
|
|
||||||
|
|
||||||
if(ent != NULL && (global_host_client == NULL || global_host_client->padding4A84 != ent)) {
|
|
||||||
for(i = 0, client = global_svs.clients; i < global_svs.allocated_client_slots; i++, client++) {
|
|
||||||
|
|
||||||
if(client->padding4A84 == ent) {
|
|
||||||
global_host_client = client;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0, client = global_svs.clients; i < global_svs.allocated_client_slots; i++, client++) {
|
|
||||||
|
|
||||||
if(client->padding00_used == 0 || (client == global_host_client && (arg_8_flags & 0x80) != 0)) { continue; }
|
|
||||||
if(ent != NULL && ent->v.groupinfo != 0 && client->padding4A84->v.groupinfo != 0) {
|
|
||||||
if((global_g_groupop == 0 && (client->padding4A84->v.groupinfo & ent->v.groupinfo) == 0) ||
|
|
||||||
(global_g_groupop == 1 && (client->padding4A84->v.groupinfo & ent->v.groupinfo) != 0)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(SV_ValidClientMulticast(client, leafnum, arg_8_flags) == 0) { continue; }
|
|
||||||
|
|
||||||
|
|
||||||
if(arg_c_bool == 0) { //reliable I think
|
|
||||||
|
|
||||||
if(client->sizebuf24AC.maxsize - client->sizebuf24AC.cursize > global_sv.sizebuf3dbd0_multicast.cursize) {
|
|
||||||
SZ_Write(&(client->sizebuf24AC), global_sv.sizebuf3dbd0_multicast.data, global_sv.sizebuf3dbd0_multicast.cursize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(client->netchan1C.netchan_message.maxsize - client->netchan1C.netchan_message.cursize > global_sv.sizebuf3dbd0_multicast.cursize) {
|
|
||||||
SZ_Write(&(client->netchan1C.netchan_message), global_sv.sizebuf3dbd0_multicast.data, global_sv.sizebuf3dbd0_multicast.cursize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SZ_Clear(&(global_sv.sizebuf3dbd0_multicast));
|
|
||||||
global_host_client = oldclient;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_HashString
|
|
||||||
// LOCATION: The SDK
|
|
||||||
// PATH: Wherever a hash table is used
|
|
||||||
//
|
|
||||||
// Hashes a string. Nothing more. Very oddly.
|
|
||||||
*/
|
|
||||||
unsigned int SV_HashString(const char * String, unsigned int max) {
|
|
||||||
|
|
||||||
unsigned int hash = 0;
|
|
||||||
unsigned char temp = tolower(*String);
|
|
||||||
|
|
||||||
while(temp != '\0') {
|
|
||||||
|
|
||||||
hash += temp | (temp << 8) | (temp << 16) | (temp << 24); //deep, complicated hashing algorithm here.
|
|
||||||
String++;
|
|
||||||
temp = tolower(*String);
|
|
||||||
}
|
|
||||||
return(hash % max);
|
|
||||||
}
|
|
||||||
void SV_AddSampleToHashedLookupTable(const char * sample, int num) {
|
|
||||||
|
|
||||||
unsigned int i, var_8_hash;
|
|
||||||
|
|
||||||
|
|
||||||
i = var_8_hash = SV_HashString(sample, 0x3FF);
|
|
||||||
|
|
||||||
while(global_sv.padding32B48[i] != 0) { //hash collision
|
|
||||||
|
|
||||||
i++;
|
|
||||||
if(i > 0x3fe) { i = 0; }
|
|
||||||
if(i == var_8_hash) {
|
|
||||||
Sys_Error("%s: No free slots in lookup table.\n", __FUNCTION__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global_sv.padding32B48[i] = num;
|
|
||||||
}
|
|
||||||
void SV_BuildHashedSoundLookupTable() {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
Q_memset(global_sv.padding32B48, 0, 0x7fe);
|
|
||||||
for(i = 0; i < 0x200; i++) {
|
|
||||||
|
|
||||||
if(global_sv.sound_precache[i] == NULL) { break; }
|
|
||||||
SV_AddSampleToHashedLookupTable(global_sv.sound_precache[i], i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
global_sv.padding33348 = 1;
|
|
||||||
}
|
|
||||||
int SV_LookupSoundIndex(const char * sample) {
|
|
||||||
|
|
||||||
unsigned int i, var_8_hash;
|
|
||||||
|
|
||||||
|
|
||||||
var_8_hash = SV_HashString(sample, 0x3FF);
|
|
||||||
|
|
||||||
if(global_sv.padding33348 == 0) {
|
|
||||||
if(global_sv.padding3bc64 == 1) {
|
|
||||||
|
|
||||||
for(i = 1; i < 0x200; i++) {
|
|
||||||
|
|
||||||
if(global_sv.sound_precache[i] == NULL) { break; }
|
|
||||||
if(Q_strcasecmp(sample, global_sv.sound_precache[i]) == 0) { return(i); }
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SV_BuildHashedSoundLookupTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
i = var_8_hash;
|
|
||||||
while(global_sv.padding32B48[i] != 0) {
|
|
||||||
|
|
||||||
if(Q_strcasecmp(sample, global_sv.sound_precache[global_sv.padding32B48[i]]) == 0) {
|
|
||||||
return(global_sv.padding32B48[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
|
||||||
if(i > 0x3fe) { i = 0; }
|
|
||||||
if(i == var_8_hash) { break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int SV_BuildSoundMsg(edict_t * ent, int channel, const char * sample, int volume, float attenuation, int flags, int pitch, const vec3_t position, sizebuf_t * sz) {
|
|
||||||
|
|
||||||
int var_4_SoundIndex;
|
|
||||||
int var_C_edictnum;
|
|
||||||
int var_8;
|
|
||||||
|
|
||||||
|
|
||||||
if(volume < 0 || volume > 255) {
|
|
||||||
Sys_Error("%s: volume = %i", __FUNCTION__, volume);
|
|
||||||
}
|
|
||||||
if(attenuation < 0 || attenuation > 4) {
|
|
||||||
Sys_Error("%s: attenuation = %d", __FUNCTION__, attenuation);
|
|
||||||
}
|
|
||||||
if(channel < 0 || channel > 7) {
|
|
||||||
Sys_Error("%s: channel = %i", __FUNCTION__, channel);
|
|
||||||
}
|
|
||||||
if(pitch < 0 || pitch > 255) {
|
|
||||||
Sys_Error("%s: pitch = %i", __FUNCTION__, pitch);
|
|
||||||
}
|
|
||||||
if(sample == NULL) { //I find it doubtful taht this can be legit.
|
|
||||||
Sys_Error("%s: NULL sample", __FUNCTION__);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sample[0] == '!') {
|
|
||||||
|
|
||||||
flags |= 0x10;
|
|
||||||
var_4_SoundIndex = Q_atoi(sample+1);
|
|
||||||
if(var_4_SoundIndex >= 0x600) {
|
|
||||||
|
|
||||||
Con_Printf("%s: Invalid sentence number %s.\n", __FUNCTION__, sample);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(sample[0] == '#') {
|
|
||||||
|
|
||||||
flags |= 0x10;
|
|
||||||
var_4_SoundIndex = Q_atoi(sample+1) + 0x600;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
var_4_SoundIndex = SV_LookupSoundIndex(sample);
|
|
||||||
if(var_4_SoundIndex == 0 || global_sv.sound_precache[var_4_SoundIndex] == NULL) {
|
|
||||||
|
|
||||||
Con_Printf("%s: Sound %s not precached.\n", __FUNCTION__, sample);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var_C_edictnum = NUM_FOR_EDICT(ent);
|
|
||||||
var_8 = flags;
|
|
||||||
if(volume != 255) { var_8 |= 1; }
|
|
||||||
if(attenuation != 1) { var_8 |= 2; }
|
|
||||||
if(pitch != 100) { var_8 |= 8; }
|
|
||||||
if(var_4_SoundIndex > 255) { var_8 |= 4; }
|
|
||||||
|
|
||||||
MSG_WriteByte(sz, 0x06);
|
|
||||||
|
|
||||||
MSG_StartBitWriting(sz);
|
|
||||||
MSG_WriteBits(var_8, 9);
|
|
||||||
if(var_8 & 1) { MSG_WriteBits(volume, 8); }
|
|
||||||
if(var_8 & 2) { MSG_WriteBits((int)(attenuation * 64), 8); }
|
|
||||||
MSG_WriteBits(channel, 3);
|
|
||||||
MSG_WriteBits(var_C_edictnum, 0x0B);
|
|
||||||
|
|
||||||
if(var_4_SoundIndex > 255) {
|
|
||||||
MSG_WriteBits(var_4_SoundIndex, 16);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MSG_WriteBits(var_4_SoundIndex, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
MSG_WriteBitVec3Coord(position);
|
|
||||||
if(var_8 & 8) { MSG_WriteBits(pitch, 8); }
|
|
||||||
|
|
||||||
MSG_EndBitWriting(sz);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
void SV_StartSound(int arg_0, edict_t * ent, int channel, const char * sample, int volume, float attenuation, int flags, int pitch) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
int var_24, var_8;
|
|
||||||
vec3_t position;
|
|
||||||
|
|
||||||
|
|
||||||
for(i = 0; i < 3; i++) {
|
|
||||||
position[i] = ent->v.origin[i] + ((ent->v.mins[i] + ent->v.maxs[i]) / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(SV_BuildSoundMsg(ent, channel, sample, volume, attenuation, flags, pitch, position, &global_sv.sizebuf3dbd0_multicast) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(channel == 6 || (flags & 0x20) != 0) { var_8 = 0; }
|
|
||||||
else { var_8 = 1; }
|
|
||||||
|
|
||||||
if(arg_0 == 1) { var_24 = 0x80; } //Basicanlly a Don't Send to Originating Player flag
|
|
||||||
else { var_24 = 0; }
|
|
||||||
|
|
||||||
if(var_8 != 0) {
|
|
||||||
SV_Multicast(ent, position, var_24 | 4, 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SV_Multicast(ent, position, var_24 | 1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HLDS_DLLEXPORT void PM_SV_PlaySound(int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch) {
|
|
||||||
|
|
||||||
SV_StartSound(1, global_host_client->padding4A84, channel, sample, volume * 255, attenuation, fFlags, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EV_PlayReliableEvent(client_t * cl, int edictindex, int eventindex, float delay, event_args_t * event) {
|
|
||||||
|
|
||||||
sizebuf_t buffer;
|
|
||||||
event_args_t nullevent, tempevent2;
|
|
||||||
char databuf[0x400];
|
|
||||||
|
|
||||||
|
|
||||||
if(cl->padding2438_IsFakeClient != 0) { return; }
|
|
||||||
|
|
||||||
buffer.debugname = "Reliable Event";
|
|
||||||
buffer.overflow = 0;
|
|
||||||
buffer.data = databuf;
|
|
||||||
buffer.maxsize = 0x400;
|
|
||||||
buffer.cursize = 0;
|
|
||||||
|
|
||||||
Q_memset(&nullevent, 0, sizeof(event_args_t));
|
|
||||||
tempevent2 = *event;
|
|
||||||
tempevent2.entindex = edictindex;
|
|
||||||
|
|
||||||
|
|
||||||
MSG_WriteByte(&buffer, 0x15);
|
|
||||||
MSG_StartBitWriting(&buffer);
|
|
||||||
MSG_WriteBits(eventindex, 0x0A);
|
|
||||||
DELTA_WriteDelta((byte *)(&nullevent), (byte *)(&tempevent2), 1, SV_LookupDelta("event_t"), 0);
|
|
||||||
|
|
||||||
if(delay != 0) {
|
|
||||||
MSG_WriteBits(1, 1);
|
|
||||||
MSG_WriteBits(delay * 100, 0x10);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MSG_WriteBits(0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
MSG_EndBitWriting(&buffer);
|
|
||||||
if(cl->netchan1C.netchan_message.cursize + buffer.cursize > cl->netchan1C.netchan_message.maxsize) {
|
|
||||||
Netchan_CreateFragments(1, &(cl->netchan1C), &buffer);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SZ_Write(&(cl->netchan1C.netchan_message), buffer.data, buffer.cursize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void EV_Playback(int flags, edict_t * passedClient, unsigned short eventindex, float delay, vec3_t origin, vec3_t angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2) {
|
|
||||||
|
|
||||||
unsigned int i, j;
|
|
||||||
int var_1c, var_20_leafnum, var_2c_index, var_7C_edictnum;
|
|
||||||
event_info_t * var_24_event_info, * var_28_event_info_p;
|
|
||||||
event_args_t var_74_event;
|
|
||||||
vec3_t var_18_vecpoint;
|
|
||||||
client_t * var_8_client;
|
|
||||||
|
|
||||||
|
|
||||||
if((flags & 0x40) != 0) { return; }
|
|
||||||
|
|
||||||
Q_memset(&var_74_event, 0, sizeof(event_args_t));
|
|
||||||
if(origin[0] != 0 || origin[1] != 0 || origin[2] != 0) {
|
|
||||||
|
|
||||||
var_74_event.origin[0] = origin[0];
|
|
||||||
var_74_event.origin[1] = origin[1];
|
|
||||||
var_74_event.origin[2] = origin[2];
|
|
||||||
var_74_event.flags |= 1;
|
|
||||||
}
|
|
||||||
if(angles[0] != 0 || angles[1] != 0 || angles[2] != 0) {
|
|
||||||
|
|
||||||
var_74_event.angles[0] = angles[0];
|
|
||||||
var_74_event.angles[1] = angles[1];
|
|
||||||
var_74_event.angles[2] = angles[2];
|
|
||||||
var_74_event.flags |= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_74_event.fparam1 = fparam1;
|
|
||||||
var_74_event.fparam2 = fparam2;
|
|
||||||
var_74_event.iparam1 = iparam1;
|
|
||||||
var_74_event.iparam2 = iparam2;
|
|
||||||
var_74_event.bparam1 = bparam1;
|
|
||||||
var_74_event.bparam2 = bparam2;
|
|
||||||
|
|
||||||
//That's that done.
|
|
||||||
if(eventindex == 0 || eventindex > 255) {
|
|
||||||
Con_Printf("%s: index %i out of range.\n", __FUNCTION__, eventindex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(global_sv.padding31348[eventindex].mem == NULL) {
|
|
||||||
Con_Printf("%s: index %i does not point to an event.\n", __FUNCTION__, eventindex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(passedClient == NULL) {
|
|
||||||
|
|
||||||
var_18_vecpoint[0] = var_74_event.origin[0];
|
|
||||||
var_18_vecpoint[1] = var_74_event.origin[1];
|
|
||||||
var_18_vecpoint[2] = var_74_event.origin[2];
|
|
||||||
var_7C_edictnum = -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
var_18_vecpoint[0] = passedClient->v.origin[0];
|
|
||||||
var_18_vecpoint[1] = passedClient->v.origin[1];
|
|
||||||
var_18_vecpoint[2] = passedClient->v.origin[2];
|
|
||||||
var_7C_edictnum = NUM_FOR_EDICT(passedClient);
|
|
||||||
|
|
||||||
if(var_7C_edictnum > 0 && (unsigned)var_7C_edictnum <= global_svs.allocated_client_slots && (passedClient->v.flags & FL_DUCKING)) {
|
|
||||||
var_74_event.ducking = 1;
|
|
||||||
}
|
|
||||||
if((var_74_event.flags & 1) == 0) {
|
|
||||||
var_74_event.origin[0] = passedClient->v.origin[0];
|
|
||||||
var_74_event.origin[1] = passedClient->v.origin[1];
|
|
||||||
var_74_event.origin[2] = passedClient->v.origin[2];
|
|
||||||
}
|
|
||||||
if((var_74_event.flags & 2) == 0) {
|
|
||||||
var_74_event.angles[0] = passedClient->v.angles[0];
|
|
||||||
var_74_event.angles[1] = passedClient->v.angles[1];
|
|
||||||
var_74_event.angles[2] = passedClient->v.angles[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var_1c = 4;
|
|
||||||
var_20_leafnum = SV_PointLeafnum(var_18_vecpoint); //This is in the QW.
|
|
||||||
|
|
||||||
for(i = 0; i < global_svs.allocated_client_slots; i++) {
|
|
||||||
|
|
||||||
var_8_client = &(global_svs.clients[i]);
|
|
||||||
if(var_8_client->padding00_used == 0 || var_8_client->padding04 == 0 ||
|
|
||||||
var_8_client->padding08 == 0 || var_8_client->padding0C_connected == 0 ||
|
|
||||||
var_8_client->padding2438_IsFakeClient != 0) {
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(passedClient != NULL && passedClient->v.groupinfo != 0 &&
|
|
||||||
var_8_client->padding4A84->v.groupinfo != 0) {
|
|
||||||
|
|
||||||
if((global_g_groupop == 0 && (var_8_client->padding4A84->v.groupinfo & passedClient->v.groupinfo) == 0) ||
|
|
||||||
(global_g_groupop == 1 && (var_8_client->padding4A84->v.groupinfo & passedClient->v.groupinfo) != 0)) {
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if((flags & 4) == 0 && passedClient != NULL &&
|
|
||||||
SV_ValidClientMulticast(var_8_client, var_20_leafnum, var_1c) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(global_host_client == var_8_client && (flags & 1) != 0 && var_8_client->cl_lw != 0) {
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if((flags & 0x10) != 0 && var_8_client->padding4A84 != passedClient) {
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if((flags & 2) != 0) {
|
|
||||||
|
|
||||||
if(passedClient == NULL) {
|
|
||||||
EV_PlayReliableEvent(var_8_client, 0, eventindex, delay, &var_74_event);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
EV_PlayReliableEvent(var_8_client, NUM_FOR_EDICT(passedClient), eventindex, delay, &var_74_event);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_24_event_info = var_8_client->events;
|
|
||||||
var_2c_index = -1;
|
|
||||||
|
|
||||||
if((flags & 8) != 0) {
|
|
||||||
for(j = 0; j < 0x40; j++) {
|
|
||||||
|
|
||||||
var_28_event_info_p = &(var_24_event_info[j]);
|
|
||||||
if(var_28_event_info_p->index == eventindex && var_7C_edictnum != -1 && var_7C_edictnum == var_28_event_info_p->entity_index) {
|
|
||||||
|
|
||||||
var_2c_index = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var_2c_index == -1) {
|
|
||||||
for(j = 0; j < 0x40; j++) {
|
|
||||||
|
|
||||||
var_28_event_info_p = &(var_24_event_info[j]);
|
|
||||||
if(var_28_event_info_p->index == 0) {
|
|
||||||
|
|
||||||
var_2c_index = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var_2c_index != -1 && j > 0x3F) {
|
|
||||||
|
|
||||||
var_28_event_info_p = &(var_24_event_info[var_2c_index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var_2c_index == -1) { continue; }
|
|
||||||
|
|
||||||
var_28_event_info_p->index = eventindex;
|
|
||||||
var_28_event_info_p->packet_index = -1;
|
|
||||||
|
|
||||||
if(passedClient == NULL) {
|
|
||||||
var_28_event_info_p->entity_index = -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var_28_event_info_p->entity_index = var_7C_edictnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_28_event_info_p->args = var_74_event;
|
|
||||||
var_28_event_info_p->fire_time = delay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void EV_SV_Playback(int flags, int clientindex, unsigned short eventindex, float delay, vec3_t origin, vec3_t angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2) {
|
|
||||||
|
|
||||||
if((flags & 0x40) != 0) { return; }
|
|
||||||
if(clientindex < 0 || (unsigned)clientindex >= global_svs.allocated_client_slots) {
|
|
||||||
|
|
||||||
Sys_Error("%s: Client index %i out of range.\n", __FUNCTION__, clientindex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EV_Playback(flags, global_svs.clients[clientindex].padding4A84, eventindex, delay, origin, angles, fparam1, fparam2, iparam1, iparam2, bparam1, bparam2);
|
|
||||||
}
|
|
||||||
HLDS_DLLEXPORT void PM_SV_PlaybackEventFull(int flags, int clientindex, unsigned short eventindex, float delay, vec3_t origin, vec3_t angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2) {
|
|
||||||
EV_SV_Playback(flags | 1, clientindex, eventindex, delay, origin, angles, fparam1, fparam2, iparam1, iparam2, bparam1, bparam2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_FullClientUpdate
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: a few
|
|
||||||
//
|
|
||||||
// Sends a packet. I don't really know what's so special about it.
|
|
||||||
*/
|
|
||||||
void SV_FullClientUpdate(client_t * client, sizebuf_t *buf) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
char info[0x100];
|
|
||||||
MD5Context_t checksum;
|
|
||||||
char hash[16];
|
|
||||||
|
|
||||||
|
|
||||||
i = client - global_svs.clients;
|
|
||||||
|
|
||||||
Q_strncpy(info, client->InfoKeyBuffer, sizeof(info)-1);
|
|
||||||
info[sizeof(info)-1] = '\0';
|
|
||||||
|
|
||||||
Info_RemovePrefixedKeys(info, '_');
|
|
||||||
|
|
||||||
MSG_WriteByte(buf, 0x0D);
|
|
||||||
MSG_WriteByte(buf, i);
|
|
||||||
MSG_WriteLong(buf, client->padding4A8C_PlayerUID);
|
|
||||||
MSG_WriteString(buf, info);
|
|
||||||
|
|
||||||
MD5Init(&checksum);
|
|
||||||
MD5Update(&checksum, client->authentication_CD_key, sizeof(client->authentication_CD_key));
|
|
||||||
MD5Final(hash, &checksum);
|
|
||||||
|
|
||||||
MSG_WriteBuf(buf, sizeof(hash), hash);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_ForceFullClientsUpdate
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_RunCmd, SV_FullUpdate_f
|
|
||||||
//
|
|
||||||
// Sends some data, bla bla bla.
|
|
||||||
*/
|
|
||||||
void SV_ForceFullClientsUpdate() {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
char buf[0x2400];
|
|
||||||
client_t * cl;
|
|
||||||
sizebuf_t sz;
|
|
||||||
|
|
||||||
sz.debugname = "Force Update";
|
|
||||||
sz.overflow = 0;
|
|
||||||
sz.data = buf;
|
|
||||||
sz.maxsize = sizeof(buf);
|
|
||||||
sz.cursize = 0;
|
|
||||||
|
|
||||||
|
|
||||||
cl = &global_svs.clients[0];
|
|
||||||
for(i = 0; i < global_svs.allocated_client_slots; i++, cl++) {
|
|
||||||
|
|
||||||
if(global_host_client != cl && cl->padding00_used == 0 &&
|
|
||||||
cl->padding0C_connected == 0 && cl->padding04 == 0) { continue; }
|
|
||||||
|
|
||||||
SV_FullClientUpdate(cl, &sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
Con_Printf("%s: Client %s started recording. Send full update.", __FUNCTION__, cl->PlayerName);
|
|
||||||
|
|
||||||
Netchan_CreateFragments(1, &(global_host_client->netchan1C), &sz);
|
|
||||||
Netchan_FragSend(&(global_host_client->netchan1C));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_BroadcastCommand
|
|
||||||
// LOCATION: SV_Send.c
|
|
||||||
// PATH: Cvar_DirectSet and SV_Serverinfo_f
|
|
||||||
//
|
|
||||||
// This sends a message to all connected clients (according to QW).
|
|
||||||
*/
|
|
||||||
void SV_BroadcastCommand(const char * format, ...) {
|
|
||||||
|
|
||||||
char array[1024]; //128 or 1024? Doesn't seem to matter.
|
|
||||||
int length;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
client_t * clients;
|
|
||||||
va_list argptr;
|
|
||||||
|
|
||||||
if(global_sv.active == 0) { return; }
|
|
||||||
|
|
||||||
array[0] = 9;
|
|
||||||
|
|
||||||
va_start(argptr, format);
|
|
||||||
length = Q_vsnprintf(array+1, 1023, format, argptr) + 1;
|
|
||||||
va_end(argptr);
|
|
||||||
|
|
||||||
//Overflow testing. vsnprintf (and all nprintfs) return the number of
|
|
||||||
//chars that would have been written if there was enough room.
|
|
||||||
//If we overflowed, this number will be greater than 1023 (1023 - 1 for
|
|
||||||
//the null and +1 for the nine). In that case we have a non-null
|
|
||||||
//terminated array and a sys error to throw.
|
|
||||||
if(length > 1023) {
|
|
||||||
Sys_Error("SV_BroadcastCommand: Overflowed when writing message.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0, clients = global_svs.clients; i < global_svs.allocated_client_slots; i++, clients++) {
|
|
||||||
|
|
||||||
if((clients->padding00_used == 0 && clients->padding0C_connected == 0 && clients->padding04 == 0) ||
|
|
||||||
(clients->padding2438_IsFakeClient != 0)) { continue; }
|
|
||||||
SZ_Write(&clients->netchan1C.netchan_message, array, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void SV_BroadcastPrintf(const char * format, ...) {
|
|
||||||
|
|
||||||
char array[1024]; //128 or 1024? Doesn't seem to matter.
|
|
||||||
int length;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
client_t * clients;
|
|
||||||
va_list argptr;
|
|
||||||
|
|
||||||
if(global_sv.active == 0) { return; }
|
|
||||||
|
|
||||||
array[0] = 8;
|
|
||||||
|
|
||||||
va_start(argptr, format);
|
|
||||||
length = Q_vsnprintf(array+1, 1023, format, argptr) + 1;
|
|
||||||
va_end(argptr);
|
|
||||||
|
|
||||||
//Overflow testing. vsnprintf (and all nprintfs) return the number of
|
|
||||||
//chars that would have been written if there was enough room.
|
|
||||||
//If we overflowed, this number will be greater than 1023 (1023 - 1 for
|
|
||||||
//the null and +1 for the nine). In that case we have a non-null
|
|
||||||
//terminated array and a sys error to throw.
|
|
||||||
if(length > 1023) {
|
|
||||||
Sys_Error("SV_BroadcastPrintf: Overflowed when writing message.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0, clients = global_svs.clients; i < global_svs.allocated_client_slots; i++, clients++) {
|
|
||||||
|
|
||||||
if((clients->padding00_used == 0 && clients->padding04 == 0) ||
|
|
||||||
(clients->padding2438_IsFakeClient != 0)) { continue; }
|
|
||||||
SZ_Write(&clients->netchan1C.netchan_message, array, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_ClientPrintf
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: Lots of kick and ban functions.
|
|
||||||
//
|
|
||||||
// Prints a client message. Not an 'l' message--some new one.
|
|
||||||
// I've simplified it by writing the data directly to the stream.
|
|
||||||
*/
|
|
||||||
void SV_ClientPrintf(const char *format, ...) {
|
|
||||||
|
|
||||||
va_list argptr;
|
|
||||||
int sizeleft, written;
|
|
||||||
|
|
||||||
|
|
||||||
if(global_host_client->padding2438_IsFakeClient) { return; }
|
|
||||||
|
|
||||||
sizeleft = global_host_client->netchan1C.netchan_message.maxsize - global_host_client->netchan1C.netchan_message.cursize;
|
|
||||||
if(sizeleft < 2) { return; } //one for the identifier, one for the null
|
|
||||||
|
|
||||||
global_host_client->netchan1C.netchan_message.data[global_host_client->netchan1C.netchan_message.cursize] = 0x08;
|
|
||||||
|
|
||||||
va_start(argptr, format);
|
|
||||||
written = Q_vsnprintf(global_host_client->netchan1C.netchan_message.data + global_host_client->netchan1C.netchan_message.cursize + 1, sizeleft - 1, format, argptr) + 1;
|
|
||||||
va_end(argptr);
|
|
||||||
|
|
||||||
if(written > sizeleft) { //Message was too big.
|
|
||||||
|
|
||||||
global_host_client->netchan1C.netchan_message.data[global_host_client->netchan1C.netchan_message.maxsize-1] = '\0';
|
|
||||||
written = sizeleft;
|
|
||||||
}
|
|
||||||
|
|
||||||
global_host_client->netchan1C.netchan_message.cursize += written + 1;
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_DropClient
|
|
||||||
// LOCATION: sv_main.c
|
|
||||||
// PATH: many
|
|
||||||
//
|
|
||||||
// Sends the packet notifying the poor client of his failure
|
|
||||||
// to live up to our expectations. Also sends the update
|
|
||||||
// to other connected clients. This is fr maintaining
|
|
||||||
// a clean client list, so it's not used if the server itself
|
|
||||||
// is terminating.
|
|
||||||
*/
|
|
||||||
void SV_DropClient(client_t * client, int ClientHasCrashed, char * message, ...) {
|
|
||||||
|
|
||||||
char array2[1024];
|
|
||||||
int i;
|
|
||||||
float tempfloat;
|
|
||||||
va_list argptr;
|
|
||||||
|
|
||||||
|
|
||||||
va_start(argptr, message);
|
|
||||||
i = Q_vsnprintf(array2, sizeof(array2)-1, message, argptr) + 1;
|
|
||||||
va_end(argptr);
|
|
||||||
|
|
||||||
if(i > (signed)sizeof(array2)) {
|
|
||||||
Con_Printf("SV_DropClientn: A client drop message had to be truncated.\n");
|
|
||||||
array2[sizeof(array2) - 1] = '\0';
|
|
||||||
i = sizeof(array2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(ClientHasCrashed == 0) {
|
|
||||||
|
|
||||||
Con_Printf("Dropped %s, reason: %s\n", client->PlayerName, array2);
|
|
||||||
|
|
||||||
if(client->padding2438_IsFakeClient == 0) {
|
|
||||||
|
|
||||||
MSG_WriteByte(&client->netchan1C.netchan_message, 2);
|
|
||||||
MSG_WriteBuf(&client->netchan1C.netchan_message, i, array2);
|
|
||||||
|
|
||||||
//The broadcast message will be shorter if needed.
|
|
||||||
if(i > 63) {
|
|
||||||
i = 64;
|
|
||||||
array2[63] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(client->padding4A84 != NULL && client->padding04 != 0) {
|
|
||||||
gEntityInterface.pfnClientDisconnect(client->padding4A84);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(client->padding2438_IsFakeClient == 0) {
|
|
||||||
Netchan_Transmit(&client->netchan1C, i, array2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tempfloat = global_realtime - client->netchan1C.first_received;
|
|
||||||
if(tempfloat >= 0) {
|
|
||||||
|
|
||||||
global_svs.padding6C++;
|
|
||||||
global_svs.padding70 += tempfloat;
|
|
||||||
}
|
|
||||||
|
|
||||||
Netchan_Clear(&client->netchan1C);
|
|
||||||
|
|
||||||
//I am ignoring a steam call. Boo to steam.
|
|
||||||
|
|
||||||
client->padding00_used = 0;
|
|
||||||
client->padding04 = 0;
|
|
||||||
client->padding08 = 0;
|
|
||||||
client->padding0C_connected = 0;
|
|
||||||
client->padding14 = 0;
|
|
||||||
client->padding2438_IsFakeClient = 0;
|
|
||||||
client->padding243C_proxy = 0;
|
|
||||||
client->PlayerName[0] = '\0';
|
|
||||||
client->padding3460_connection_started = global_realtime;
|
|
||||||
|
|
||||||
COM_ClearCustomizationList(&client->padding4D30);
|
|
||||||
|
|
||||||
client->padding4A84 = NULL;
|
|
||||||
|
|
||||||
memset(client->InfoKeyBuffer, 0, 0x100);
|
|
||||||
memset(client->UnknownStruct4DE0, 0, 0x100);
|
|
||||||
|
|
||||||
SV_FullClientUpdate(client, &global_sv.sizebuf3CC1C);
|
|
||||||
//NotifyDedicatedServerUI, that's surely just printing stuff, ignored.
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_RejectConnection
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: All over
|
|
||||||
//
|
|
||||||
// So Long, Farewell, Auf Wiedersehen, Goodbye.
|
|
||||||
*/
|
|
||||||
void SV_RejectConnection(netadr_t * client, char * message, ...) {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
char TerminationMessage[1024];
|
|
||||||
va_list argptr;
|
|
||||||
|
|
||||||
|
|
||||||
va_start(argptr, message);
|
|
||||||
i = Q_vsnprintf(TerminationMessage, sizeof(TerminationMessage) - 1, message, argptr);
|
|
||||||
va_end(argptr);
|
|
||||||
|
|
||||||
// remember, 'i' holds the number of bytes that WOULD have been written, had
|
|
||||||
// the buffer been infinite.
|
|
||||||
|
|
||||||
if(i > sizeof(TerminationMessage) - 1) {
|
|
||||||
Con_Printf("SV_RejectConnection: A client rejection message had to be truncated. What, one kilo isn't ENOUGH?\n");
|
|
||||||
TerminationMessage[sizeof(TerminationMessage) - 1] = '\0';
|
|
||||||
i = sizeof(TerminationMessage) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SZ_Clear(&global_net_message);
|
|
||||||
|
|
||||||
MSG_WriteLong(&global_net_message, 0xFFFFFFFF);
|
|
||||||
MSG_WriteByte(&global_net_message, 57);
|
|
||||||
MSG_WriteBuf(&global_net_message, i, TerminationMessage);
|
|
||||||
NET_SendPacket(1, global_net_message.cursize, global_net_message.data, *client);
|
|
||||||
|
|
||||||
//this also calls _WON_RemoveUserbyAddress.
|
|
||||||
}
|
|
||||||
void SV_RejectConnectionForPassword(netadr_t * client) {
|
|
||||||
|
|
||||||
SZ_Clear(&global_net_message);
|
|
||||||
|
|
||||||
MSG_WriteLong(&global_net_message, 0xFFFFFFFF);
|
|
||||||
MSG_WriteByte(&global_net_message, 56);
|
|
||||||
MSG_WriteString(&global_net_message, "BADPASSWORD");
|
|
||||||
NET_SendPacket(1, global_net_message.cursize, global_net_message.data, *client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/* So how does a frame go? Usually somewhere along the lines of
|
|
||||||
// GetPacket->ProcessPacket->MoveEveryone->Broadcasthanges. That fourth step
|
|
||||||
// is what these functions are for.
|
|
||||||
//
|
|
||||||
// An odd quirk is the large number of sould messages. The reasoning is those
|
|
||||||
// are usually called in the "BroadcastThingies" stage, and don't fit well
|
|
||||||
// when placed in a "ProcessPacket" file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_MULTICAST_HEADER
|
|
||||||
#define OSHLDS_SV_MULTICAST_HEADER
|
|
||||||
|
|
||||||
#include "sizebuf.h"
|
|
||||||
#include "edict.h"
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
#include "NET.h"
|
|
||||||
|
|
||||||
void SV_Multicast(edict_t *, vec3_t, int, int);
|
|
||||||
int SV_BuildSoundMsg(edict_t *, int, const char *, int, float, int, int, const vec3_t, sizebuf_t *);
|
|
||||||
void SV_StartSound(int, edict_t *, int, const char *, int, float, int, int);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void PM_SV_PlaySound(int, const char *, float, float, int, int);
|
|
||||||
HLDS_DLLEXPORT void PM_SV_PlaybackEventFull(int, int, unsigned short, float, vec3_t, vec3_t, float, float, int, int, int, int);
|
|
||||||
HLDS_DLLEXPORT void EV_Playback(int, edict_t *, unsigned short, float, vec3_t, vec3_t, float, float, int, int, int, int);
|
|
||||||
|
|
||||||
void SV_BroadcastCommand(const char * format, ...);
|
|
||||||
void SV_BroadcastPrintf(const char * format, ...);
|
|
||||||
void SV_ClientPrintf(const char * format, ...);
|
|
||||||
void SV_DropClient(client_t *, int, char *, ...);
|
|
||||||
|
|
||||||
void SV_FullClientUpdate(client_t *, sizebuf_t *);
|
|
||||||
void SV_ForceFullClientsUpdate();
|
|
||||||
|
|
||||||
void SV_RejectConnection(netadr_t *, char *, ...);
|
|
||||||
void SV_RejectConnectionForPassword(netadr_t *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,912 +0,0 @@
|
|||||||
#include "SV_move.h"
|
|
||||||
|
|
||||||
#include "host.h"
|
|
||||||
#include "Modding.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "R.h"
|
|
||||||
#include "random.h"
|
|
||||||
#include "SV_mcast.h"
|
|
||||||
#include "SV_phys.h"
|
|
||||||
#include "world.h"
|
|
||||||
|
|
||||||
/*** Things with 'Move' in the title ***/
|
|
||||||
/* DESCRIPTION: SV_ClipMoveToEntity/SV_SingleClipMoveToEntity
|
|
||||||
// LOCATION: world.c
|
|
||||||
// PATH: Mostly in this file.
|
|
||||||
//
|
|
||||||
// SV_ClipMoveToEntity is a proxy (and only access point) for the next one.
|
|
||||||
//
|
|
||||||
// The function seems to be related to collision detection.
|
|
||||||
*/
|
|
||||||
void SV_SingleClipMoveToEntity(edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t * Outgoing_Trace) {
|
|
||||||
|
|
||||||
vec3_t var_c;
|
|
||||||
vec3_t var_18;
|
|
||||||
vec3_t var_24;
|
|
||||||
hull_t * var_28;
|
|
||||||
// int var_2c;
|
|
||||||
int var_30;
|
|
||||||
int var_34;
|
|
||||||
int var_38;
|
|
||||||
|
|
||||||
vec3_t forward;
|
|
||||||
vec3_t right;
|
|
||||||
vec3_t up;
|
|
||||||
vec3_t var_68;
|
|
||||||
int var_6c;
|
|
||||||
trace_t var_a4;
|
|
||||||
vec3_t var_bc;
|
|
||||||
vec3_t var_c8;
|
|
||||||
vec3_t var_d4;
|
|
||||||
|
|
||||||
Q_memset(Outgoing_Trace, 0, sizeof(trace_t));
|
|
||||||
|
|
||||||
Outgoing_Trace->fraction = 1.0;
|
|
||||||
Outgoing_Trace->allsolid = 1;
|
|
||||||
|
|
||||||
Outgoing_Trace->endpos[0] = end[0];
|
|
||||||
Outgoing_Trace->endpos[1] = end[1];
|
|
||||||
Outgoing_Trace->endpos[2] = end[2];
|
|
||||||
|
|
||||||
if(global_sv.models[ent->v.modelindex]->modeltype == 3) {
|
|
||||||
//taken: 1616, -528, 127.97 endpos
|
|
||||||
|
|
||||||
var_28 = SV_HullForStudioModel(ent, mins, maxs, var_c, &var_30);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var_28 = SV_HullForEntity(ent, mins, maxs, var_c);
|
|
||||||
var_30 = 1; //if model?
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorSubtract(start, var_c, var_18);
|
|
||||||
VectorSubtract(end, var_c, var_24);
|
|
||||||
|
|
||||||
if((ent->v.solid != SOLID_BSP) ||
|
|
||||||
(ent->v.angles[0] == 0 && ent->v.angles[1] == 0 && ent->v.angles[2] == 0)) {
|
|
||||||
|
|
||||||
//taken
|
|
||||||
var_38 = 0; //rotated prob
|
|
||||||
}
|
|
||||||
else { var_38 = 1; }
|
|
||||||
|
|
||||||
if(var_38) { //This is another function in QW.
|
|
||||||
|
|
||||||
AngleVectors(ent->v.angles, forward, right, up); //v.angles is def +58.
|
|
||||||
|
|
||||||
VectorCopy(var_18, var_68);
|
|
||||||
|
|
||||||
var_18[0] = DotProduct(var_68, forward);
|
|
||||||
var_18[1] = -DotProduct(var_68, right);
|
|
||||||
var_18[2] = DotProduct(var_68, up);
|
|
||||||
|
|
||||||
VectorCopy(var_24, var_68);
|
|
||||||
|
|
||||||
var_24[0] = DotProduct(var_68, forward);
|
|
||||||
var_24[1] = -DotProduct(var_68, right);
|
|
||||||
var_24[2] = DotProduct(var_68, up);
|
|
||||||
} //Curiously enough, I'm taking linear algebra right now. I hate it.
|
|
||||||
|
|
||||||
//= 20
|
|
||||||
if(var_30 == 1) {
|
|
||||||
SV_RecursiveHullCheck(var_28, var_28->firstclipnode, 0, 1.0, var_18, var_24, Outgoing_Trace);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for(var_6c = 0, var_34 = 0; var_34 < var_30; var_34++) {
|
|
||||||
|
|
||||||
Q_memset(&var_a4, 0, sizeof(trace_t));
|
|
||||||
var_a4.fraction = 1.0;
|
|
||||||
var_a4.allsolid = 1;
|
|
||||||
VectorCopy(end, var_a4.endpos);
|
|
||||||
|
|
||||||
SV_RecursiveHullCheck(&(var_28[var_34]), var_28[var_34].firstclipnode, 0, 1.0, var_18, var_24, &var_a4);
|
|
||||||
|
|
||||||
if(var_34 != 0 && var_a4.startsolid == 0 && var_a4.allsolid == 0 &&
|
|
||||||
var_a4.fraction > Outgoing_Trace->fraction) { continue; }
|
|
||||||
|
|
||||||
if(Outgoing_Trace->startsolid == 0) {
|
|
||||||
Q_memcpy(Outgoing_Trace, &var_a4, sizeof(trace_t));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Q_memcpy(Outgoing_Trace, &var_a4, sizeof(trace_t)); //Probably could be a bit more efficient here.
|
|
||||||
Outgoing_Trace->startsolid = 1;
|
|
||||||
}
|
|
||||||
var_6c = var_34;
|
|
||||||
}
|
|
||||||
Outgoing_Trace->hitgroup = SV_HitgroupForStudioHull(var_6c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Outgoing_Trace->fraction != 1.0) {
|
|
||||||
if(var_38 != 0) {
|
|
||||||
|
|
||||||
AngleVectorsTranspose(ent->v.angles, var_68, var_bc, var_c8);
|
|
||||||
|
|
||||||
VectorCopy(Outgoing_Trace->plane.normal, var_d4);
|
|
||||||
Outgoing_Trace->plane.normal[0] = DotProduct(var_d4, var_68);
|
|
||||||
Outgoing_Trace->plane.normal[1] = -DotProduct(var_d4, var_bc);
|
|
||||||
Outgoing_Trace->plane.normal[2] = DotProduct(var_d4, var_c8);
|
|
||||||
}
|
|
||||||
//Scaling, clearly.
|
|
||||||
Outgoing_Trace->endpos[0] = start[0] + (Outgoing_Trace->fraction * (end[0] - start[0]));
|
|
||||||
Outgoing_Trace->endpos[1] = start[1] + (Outgoing_Trace->fraction * (end[1] - start[1]));
|
|
||||||
Outgoing_Trace->endpos[2] = start[2] + (Outgoing_Trace->fraction * (end[2] - start[2]));
|
|
||||||
}
|
|
||||||
if(Outgoing_Trace->fraction < 1.0 || Outgoing_Trace->startsolid != 0) {
|
|
||||||
Outgoing_Trace->pHit = ent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace_t * SV_ClipMoveToEntity(trace_t * Outgoing_Trace, edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end) {
|
|
||||||
|
|
||||||
SV_SingleClipMoveToEntity(ent, start, mins, maxs, end, Outgoing_Trace);
|
|
||||||
return(Outgoing_Trace);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_MoveBounds
|
|
||||||
// LOCATION: world.c
|
|
||||||
// PATH:SV_Move (and SV_MoveNoEnts)
|
|
||||||
//
|
|
||||||
// There are a lot of entities. Do we really need to test and see if we
|
|
||||||
// collided against each and every one? No, we don't, and I *think*
|
|
||||||
// that's what this function is for.
|
|
||||||
//
|
|
||||||
// We can force HL to check against all entities by setting the values to
|
|
||||||
// really high numbers. Said so in the QW code...
|
|
||||||
*/
|
|
||||||
void SV_MoveBounds(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, vec3_t boxmins, vec3_t boxmaxs) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i=0 ; i<3 ; i++) {
|
|
||||||
if (end[i] > start[i]) {
|
|
||||||
boxmins[i] = start[i] + mins[i] - 1;
|
|
||||||
boxmaxs[i] = end[i] + maxs[i] + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
boxmins[i] = end[i] + mins[i] - 1;
|
|
||||||
boxmaxs[i] = start[i] + maxs[i] + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_Move
|
|
||||||
// LOCATION: world.c
|
|
||||||
// PATH: A few places in the game logic
|
|
||||||
//
|
|
||||||
// Seems to be responsible for handling movements in the virtual world.
|
|
||||||
// Returns a trace_t struct, which is actually performed with some compiler
|
|
||||||
// magic--arg0 is used to store the pointer, and it's copied upon the
|
|
||||||
// function's return.
|
|
||||||
*/
|
|
||||||
trace_t SV_Move(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict, int hullnumthing) {
|
|
||||||
|
|
||||||
moveclip_t clip;
|
|
||||||
vec3_t var_94_end; //identical to declaring vec_t var_94[3]
|
|
||||||
float var_98;
|
|
||||||
|
|
||||||
memset(&clip, 0, sizeof(moveclip_t));
|
|
||||||
SV_ClipMoveToEntity(&(clip.trace), global_sv.edicts, start, mins, maxs, end);
|
|
||||||
|
|
||||||
if(clip.trace.fraction != 0) {
|
|
||||||
|
|
||||||
var_94_end[0] = clip.trace.endpos[0];
|
|
||||||
var_94_end[1] = clip.trace.endpos[1];
|
|
||||||
var_94_end[2] = clip.trace.endpos[2];
|
|
||||||
|
|
||||||
clip.end = var_94_end;
|
|
||||||
var_98 = clip.trace.fraction;
|
|
||||||
clip.trace.fraction = 1.0;
|
|
||||||
clip.start = start;
|
|
||||||
clip.mins = mins;
|
|
||||||
clip.maxs = maxs;
|
|
||||||
clip.type1 = type & 0xff; //Dunno why...
|
|
||||||
clip.type2 = type << 8;
|
|
||||||
clip.passedict = passedict;
|
|
||||||
clip.hullnum = hullnumthing;
|
|
||||||
|
|
||||||
if(type == 2) {
|
|
||||||
|
|
||||||
clip.mins2[0] = -15.0;
|
|
||||||
clip.mins2[1] = -15.0;
|
|
||||||
clip.mins2[2] = -15.0;
|
|
||||||
clip.maxs2[0] = 15.0;
|
|
||||||
clip.maxs2[1] = 15.0;
|
|
||||||
clip.maxs2[2] = 15.0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
clip.mins2[0] = mins[0];
|
|
||||||
clip.mins2[1] = mins[1];
|
|
||||||
clip.mins2[2] = mins[2];
|
|
||||||
clip.maxs2[0] = maxs[0];
|
|
||||||
clip.maxs2[1] = maxs[1];
|
|
||||||
clip.maxs2[2] = maxs[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
SV_MoveBounds(start, clip.mins2, clip.maxs2, var_94_end, clip.boxmins, clip.boxmaxs);
|
|
||||||
SV_ClipToLinks(global_sv_areanodes, &clip);
|
|
||||||
|
|
||||||
clip.trace.fraction *= var_98;
|
|
||||||
|
|
||||||
gGlobalVariables.trace_ent = clip.trace.pHit;
|
|
||||||
}
|
|
||||||
return(clip.trace);
|
|
||||||
}/* DESCRIPTION: SV_MoveNoEnts
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: PF_walkmove_I->SV_movetest
|
|
||||||
//
|
|
||||||
// Same as above, but does not check for collision with entities.
|
|
||||||
*/
|
|
||||||
trace_t SV_MoveNoEnts(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict) {
|
|
||||||
|
|
||||||
moveclip_t clip;
|
|
||||||
vec3_t tempend; //identical to declaring vec_t var_94[3]
|
|
||||||
float tempfraction;
|
|
||||||
|
|
||||||
|
|
||||||
memset(&clip, 0, sizeof(moveclip_t));
|
|
||||||
SV_ClipMoveToEntity(&(clip.trace), global_sv.edicts, start, mins, maxs, end);
|
|
||||||
|
|
||||||
if(clip.trace.fraction != 0) {
|
|
||||||
|
|
||||||
tempend[0] = clip.trace.endpos[0];
|
|
||||||
tempend[1] = clip.trace.endpos[1];
|
|
||||||
tempend[2] = clip.trace.endpos[2];
|
|
||||||
|
|
||||||
clip.end = tempend;
|
|
||||||
tempfraction = clip.trace.fraction;
|
|
||||||
clip.trace.fraction = 1.0;
|
|
||||||
clip.start = start;
|
|
||||||
clip.mins = mins;
|
|
||||||
clip.maxs = maxs;
|
|
||||||
clip.type1 = type & 0xff;
|
|
||||||
clip.type2 = type << 8;
|
|
||||||
clip.passedict = passedict;
|
|
||||||
clip.hullnum = 0;
|
|
||||||
|
|
||||||
clip.mins2[0] = mins[0];
|
|
||||||
clip.mins2[1] = mins[1];
|
|
||||||
clip.mins2[2] = mins[2];
|
|
||||||
clip.maxs2[0] = maxs[0];
|
|
||||||
clip.maxs2[1] = maxs[1];
|
|
||||||
clip.maxs2[2] = maxs[2];
|
|
||||||
|
|
||||||
SV_MoveBounds(start, clip.mins2, clip.maxs2, tempend, clip.boxmins, clip.boxmaxs);
|
|
||||||
SV_ClipToWorldBrush(global_sv_areanodes, &clip);
|
|
||||||
|
|
||||||
clip.trace.fraction *= tempfraction;
|
|
||||||
gGlobalVariables.trace_ent = clip.trace.pHit;
|
|
||||||
}
|
|
||||||
return(clip.trace);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PF_WaterMove(edict_t * ent) {
|
|
||||||
|
|
||||||
double var_10;
|
|
||||||
int var_4_flags;
|
|
||||||
int var_8_waterlevel;
|
|
||||||
int var_c_watertype;
|
|
||||||
// double var_14; //some sort of damage counter, but it keeps not being used...
|
|
||||||
|
|
||||||
|
|
||||||
if(ent->v.movetype == MOVETYPE_NOCLIP) {
|
|
||||||
|
|
||||||
ent->v.air_finished = 12 + global_sv.time0c;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ent->v.health <= 0) { return; }
|
|
||||||
|
|
||||||
if(ent->v.deadflag == 0) {
|
|
||||||
var_10 = 3;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var_10 = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_4_flags = ent->v.flags;
|
|
||||||
var_8_waterlevel = ent->v.waterlevel;
|
|
||||||
var_c_watertype = ent->v.watertype;
|
|
||||||
|
|
||||||
//This area is almost but not quite entirely unlike the drowning code in the SDK.
|
|
||||||
if((var_4_flags & (FL_IMMUNE_WATER | FL_GODMODE)) == 0) { //Gods don't drown, unless they're Bruce Willis
|
|
||||||
|
|
||||||
if(((var_4_flags & FL_SWIM) && var_8_waterlevel > var_10) ||
|
|
||||||
var_8_waterlevel <= var_10) {
|
|
||||||
|
|
||||||
if(ent->v.air_finished > global_sv.time0c && ent->v.pain_finished > global_sv.time0c) {
|
|
||||||
|
|
||||||
ent->v.dmg += 2;
|
|
||||||
if(ent->v.dmg < 15) {
|
|
||||||
|
|
||||||
ent->v.dmg = 10; //wha?
|
|
||||||
}
|
|
||||||
|
|
||||||
//var_14 = ent->v.dmg;
|
|
||||||
ent->v.pain_finished = 1 + global_sv.time0c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
// if(ent->v.air_finished <= global_sv.time0c) {
|
|
||||||
// if(ent->v.air_finished <= 0 + global_sv.time0c) { }
|
|
||||||
// }
|
|
||||||
|
|
||||||
ent->v.air_finished = 12 + global_sv.time0c;
|
|
||||||
ent->v.dmg = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//This is asmess
|
|
||||||
if(var_8_waterlevel == 0) {
|
|
||||||
|
|
||||||
if((var_4_flags & FL_INWATER) != 0) {
|
|
||||||
|
|
||||||
//Leave the water.
|
|
||||||
switch(RandomLong(0, 3)) {
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade1.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade2.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade3.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade4.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->v.flags = var_4_flags & ~FL_INWATER;
|
|
||||||
}
|
|
||||||
ent->v.air_finished = 12 + global_sv.time0c;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(var_c_watertype == Q1CONTENTS_LAVA) { //aah, it stings and burns
|
|
||||||
if(((var_4_flags & (FL_IMMUNE_LAVA | FL_GODMODE)) == 0) &&
|
|
||||||
ent->v.dmgtime < global_sv.time0c) {
|
|
||||||
|
|
||||||
if(ent->v.radsuit_finished < global_sv.time0c) {
|
|
||||||
ent->v.dmgtime = global_sv.time0c + 0.2;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ent->v.dmgtime = global_sv.time0c + 1.0;
|
|
||||||
}
|
|
||||||
// var_14 = var_8_waterlevel * 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(var_c_watertype == Q1CONTENTS_SLIME) {
|
|
||||||
|
|
||||||
if(((var_4_flags & (FL_IMMUNE_SLIME | FL_GODMODE)) == 0) &&
|
|
||||||
ent->v.dmgtime < global_sv.time0c &&
|
|
||||||
ent->v.radsuit_finished < global_sv.time0c) {
|
|
||||||
|
|
||||||
ent->v.dmgtime = global_sv.time0c + 1.0;
|
|
||||||
// var_14 = var_8_waterlevel * 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if((var_4_flags & FL_INWATER) == 0) {
|
|
||||||
|
|
||||||
if(var_c_watertype == Q1CONTENTS_WATER) {
|
|
||||||
|
|
||||||
switch(RandomLong(0, 3)) {
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade1.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade2.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade3.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
SV_StartSound(0, ent, 4, "player/pl_wade4.wav", 255, 0.8, 0, 100);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->v.flags = var_4_flags | FL_INWATER;
|
|
||||||
ent->v.dmgtime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((var_4_flags & FL_WATERJUMP) == 0) {
|
|
||||||
|
|
||||||
VectorMA(ent->v.velocity, (ent->v.waterlevel * -0.8 * host_frametime), ent->v.velocity, ent->v.velocity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_movestep/movetest
|
|
||||||
// LOCATION: sv_move.c
|
|
||||||
// PATH: PF_walkmove_I
|
|
||||||
//
|
|
||||||
// (from QW): Called by monster program code.
|
|
||||||
// The move will be adjusted for slopes and stairs, but if the move isn't
|
|
||||||
// possible, no move is done, false is returned, and
|
|
||||||
// pr_global_struct->trace_normal is set to the normal of the blocking wall
|
|
||||||
*/
|
|
||||||
qboolean SV_movestep(edict_t *ent, vec3_t move, qboolean relink) {
|
|
||||||
|
|
||||||
int i, var_6C_hullnum;
|
|
||||||
float dz;
|
|
||||||
trace_t trace;
|
|
||||||
vec3_t oldorg, neworg, end;
|
|
||||||
edict_t * enemy;
|
|
||||||
|
|
||||||
|
|
||||||
if(ent->v.flags & FL_MONSTERCLIP) { //Don't know what one has to do with the other.
|
|
||||||
var_6C_hullnum = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var_6C_hullnum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
oldorg[0] = ent->v.origin[0];
|
|
||||||
oldorg[1] = ent->v.origin[1];
|
|
||||||
oldorg[2] = ent->v.origin[2];
|
|
||||||
|
|
||||||
neworg[0] = ent->v.origin[0] + move[0];
|
|
||||||
neworg[1] = ent->v.origin[1] + move[1];
|
|
||||||
neworg[2] = ent->v.origin[2] + move[2];
|
|
||||||
|
|
||||||
|
|
||||||
//well, try it. Flying and swimming monsters are easiest.
|
|
||||||
if(ent->v.flags & (FL_SWIM | FL_FLY)) {
|
|
||||||
|
|
||||||
// try one move with vertical motion, then one without
|
|
||||||
for(i = 0; i < 2; i++) {
|
|
||||||
|
|
||||||
neworg[0] = ent->v.origin[0] + move[0];
|
|
||||||
neworg[1] = ent->v.origin[1] + move[1];
|
|
||||||
neworg[2] = ent->v.origin[2] + move[2];
|
|
||||||
|
|
||||||
enemy = ent->v.enemy;
|
|
||||||
if(i == 0 && enemy != NULL) {
|
|
||||||
|
|
||||||
dz = ent->v.origin[2] - enemy->v.origin[2];
|
|
||||||
|
|
||||||
if(dz > 40) { neworg[2] -= 8; }
|
|
||||||
else if(dz < 30) { neworg[2] += 8; }
|
|
||||||
}
|
|
||||||
|
|
||||||
trace = SV_Move(ent->v.origin, ent->v.mins, ent->v.maxs, neworg, 0, ent, var_6C_hullnum);
|
|
||||||
|
|
||||||
if(trace.fraction == 1) { //yaay
|
|
||||||
|
|
||||||
global_g_groupmask = ent->v.groupinfo;
|
|
||||||
|
|
||||||
if((ent->v.flags & FL_SWIM) && SV_PointContents(trace.endpos) == Q1CONTENTS_EMPTY) {
|
|
||||||
return(0); //That move takes us out of the water. Apparently though, it's okay to travel into solids, lava, sky, etc :)
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->v.origin[0] = trace.endpos[0];
|
|
||||||
ent->v.origin[1] = trace.endpos[1];
|
|
||||||
ent->v.origin[2] = trace.endpos[2];
|
|
||||||
|
|
||||||
if(relink != 0) {
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
}
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(enemy == NULL) { break; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
dz = cvar_sv_stepsize.value;
|
|
||||||
neworg[2] += dz;
|
|
||||||
end[0] = neworg[0];
|
|
||||||
end[1] = neworg[1];
|
|
||||||
end[2] = neworg[2];
|
|
||||||
end[2] -= dz*2;
|
|
||||||
|
|
||||||
trace = SV_Move(neworg, ent->v.mins, ent->v.maxs, end, 0, ent, var_6C_hullnum);
|
|
||||||
if(trace.allsolid != 0) { return(0); }
|
|
||||||
|
|
||||||
if(trace.startsolid != 0) {
|
|
||||||
|
|
||||||
neworg[2] -= dz;
|
|
||||||
|
|
||||||
trace = SV_Move(neworg, ent->v.mins, ent->v.maxs, end, 0, ent, var_6C_hullnum);
|
|
||||||
|
|
||||||
if(trace.allsolid != 0 || trace.startsolid != 0) { return(0); }
|
|
||||||
}
|
|
||||||
|
|
||||||
if(trace.fraction == 1) {
|
|
||||||
if(ent->v.flags & FL_PARTIALGROUND) { //Whoa, where'd the ground go?
|
|
||||||
|
|
||||||
ent->v.origin[0] += move[0];
|
|
||||||
ent->v.origin[1] += move[1];
|
|
||||||
ent->v.origin[2] += move[2];
|
|
||||||
|
|
||||||
if(relink != 0) {
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
}
|
|
||||||
ent->v.flags &= ~FL_ONGROUND;
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0); //Fell off like a green koopa.
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
ent->v.origin[0] = trace.endpos[0];
|
|
||||||
ent->v.origin[1] = trace.endpos[1];
|
|
||||||
ent->v.origin[2] = trace.endpos[2];
|
|
||||||
|
|
||||||
if(SV_CheckBottom(ent) == 0) {
|
|
||||||
if(ent->v.flags & FL_PARTIALGROUND) {
|
|
||||||
|
|
||||||
if(relink != 0) {
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
}
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->v.origin[0] = oldorg[0];
|
|
||||||
ent->v.origin[1] = oldorg[1];
|
|
||||||
ent->v.origin[2] = oldorg[2];
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(ent->v.flags & FL_PARTIALGROUND) {
|
|
||||||
ent->v.flags &= ~FL_PARTIALGROUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->v.groundentity = trace.pHit;
|
|
||||||
|
|
||||||
if(relink != 0) {
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
}
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qboolean SV_movetest(edict_t *ent, vec3_t move, qboolean relink) {
|
|
||||||
|
|
||||||
float temp;
|
|
||||||
vec3_t oldorg, neworg, end;
|
|
||||||
trace_t trace;
|
|
||||||
|
|
||||||
|
|
||||||
oldorg[0] = ent->v.origin[0];
|
|
||||||
oldorg[1] = ent->v.origin[1];
|
|
||||||
oldorg[2] = ent->v.origin[2];
|
|
||||||
|
|
||||||
neworg[0] = ent->v.origin[0] + move[0];
|
|
||||||
neworg[1] = ent->v.origin[1] + move[1];
|
|
||||||
neworg[2] = ent->v.origin[2] + move[2];
|
|
||||||
|
|
||||||
temp = cvar_sv_stepsize.value;
|
|
||||||
|
|
||||||
neworg[2] += temp;
|
|
||||||
end[0] = neworg[0];
|
|
||||||
end[1] = neworg[1];
|
|
||||||
end[2] = neworg[2];
|
|
||||||
end[2] -= temp*2;
|
|
||||||
|
|
||||||
trace = SV_MoveNoEnts(neworg, ent->v.mins, ent->v.maxs, end, 0, ent);
|
|
||||||
|
|
||||||
if(trace.allsolid != 0) { return(0); }
|
|
||||||
if(trace.startsolid != 0) {
|
|
||||||
|
|
||||||
neworg[2] -= temp;
|
|
||||||
|
|
||||||
trace = SV_MoveNoEnts(neworg, ent->v.mins, ent->v.maxs, end, 0, ent);
|
|
||||||
|
|
||||||
if(trace.allsolid != 0 || trace.startsolid != 0) { return(0); }
|
|
||||||
}
|
|
||||||
|
|
||||||
if(trace.fraction == 1) {
|
|
||||||
if(ent->v.flags & FL_PARTIALGROUND) {
|
|
||||||
ent->v.origin[0] += move[0];
|
|
||||||
ent->v.origin[1] += move[1];
|
|
||||||
ent->v.origin[2] += move[2];
|
|
||||||
|
|
||||||
if(relink != 0) {
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
}
|
|
||||||
ent->v.flags &= ~FL_ONGROUND;
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
ent->v.origin[0] = trace.endpos[0];
|
|
||||||
ent->v.origin[1] = trace.endpos[1];
|
|
||||||
ent->v.origin[2] = trace.endpos[2];
|
|
||||||
|
|
||||||
if(SV_CheckBottom(ent) == 0) {
|
|
||||||
if(ent->v.flags & FL_PARTIALGROUND) {
|
|
||||||
|
|
||||||
if(relink != 0) {
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
}
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->v.origin[0] = oldorg[0];
|
|
||||||
ent->v.origin[1] = oldorg[1];
|
|
||||||
ent->v.origin[2] = oldorg[2];
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(ent->v.flags & FL_PARTIALGROUND) {
|
|
||||||
ent->v.flags &= ~FL_PARTIALGROUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->v.groundentity = trace.pHit;
|
|
||||||
|
|
||||||
if(relink != 0) {
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
}
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SV_FixCheckBottom(edict_t *ent) {
|
|
||||||
|
|
||||||
Con_Printf("%s called.\n", __FUNCTION__);
|
|
||||||
ent->v.flags |= FL_PARTIALGROUND;
|
|
||||||
}
|
|
||||||
qboolean SV_StepDirection(edict_t *ent, float yaw, float dist) {
|
|
||||||
|
|
||||||
int ret;
|
|
||||||
vec3_t move;
|
|
||||||
|
|
||||||
|
|
||||||
yaw = yaw * M_PI * 2.0 / 360.0;
|
|
||||||
move[0] = cos(yaw) * dist;
|
|
||||||
move[1] = sin(yaw) * dist;
|
|
||||||
move[2] = 0;
|
|
||||||
|
|
||||||
ret = SV_movestep(ent, move, 0);
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
|
|
||||||
return(ret);
|
|
||||||
}
|
|
||||||
qboolean SV_FlyDirection(edict_t *ent, vec3_t move) {
|
|
||||||
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
|
|
||||||
ret = SV_movestep(ent, move, 0);
|
|
||||||
SV_LinkEdict(ent, 1);
|
|
||||||
|
|
||||||
return(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SV_NewChaseDir2(edict_t *actor, vec3_t destination, float dist) {
|
|
||||||
|
|
||||||
float deltax, deltay;
|
|
||||||
float tempdir, olddir, turnaround;
|
|
||||||
vec3_t d;
|
|
||||||
|
|
||||||
olddir = anglemod(((int)(actor->v.ideal_yaw / 45.0)) * 45.0); //So, we're shaving down some of the precision. Ohkay.
|
|
||||||
turnaround = anglemod(olddir - 180);
|
|
||||||
|
|
||||||
deltax = destination[0] - actor->v.origin[0];
|
|
||||||
deltay = destination[1] - actor->v.origin[1];
|
|
||||||
|
|
||||||
if(deltax > 10) { d[1]= 0; }
|
|
||||||
else if(deltax < -10) { d[1]= 180; }
|
|
||||||
else { d[1] = -1; } //DI_NODIR, so in this function, -1 is a reserved 'null' like value.
|
|
||||||
|
|
||||||
if(deltay < -10) { d[2] = 270; }
|
|
||||||
else if(deltay > 10) { d[2] = 90; }
|
|
||||||
else { d[2] = -1; }
|
|
||||||
|
|
||||||
// try direct route
|
|
||||||
if(d[1] != -1 && d[2] != -1) {
|
|
||||||
|
|
||||||
if(d[1] == 0) {
|
|
||||||
if(d[2] == 90) { tempdir = 45; }
|
|
||||||
else { tempdir = 315; }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(d[2] == 90) { tempdir = 135; }
|
|
||||||
else { tempdir = 215; }
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tempdir != turnaround && SV_StepDirection(actor, tempdir, dist) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// try other directions
|
|
||||||
if(RandomLong(0, 1) != 0 || fabs(deltay) > fabs(deltax)) { //These were originally cast as int before compared. I cannot think of any compelling reason to do so.
|
|
||||||
|
|
||||||
tempdir = d[1];
|
|
||||||
d[1] = d[2];
|
|
||||||
d[2] = tempdir;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(d[1] != -1 && d[1] != turnaround && SV_StepDirection(actor, d[1], dist) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(d[2] != -1 && d[2] != turnaround && SV_StepDirection(actor, d[2], dist) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* there is no direct path to the player, so pick another direction */
|
|
||||||
if(olddir != -1 && SV_StepDirection(actor, olddir, dist) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Fine, just run somewhere.
|
|
||||||
if(RandomLong(0, 1) != 0) {
|
|
||||||
for(tempdir = 0; tempdir <= 315; tempdir += 45) {
|
|
||||||
if(tempdir != turnaround && SV_StepDirection(actor, tempdir, dist) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for(tempdir = 315; tempdir >= 0; tempdir -= 45) {
|
|
||||||
if(tempdir != turnaround && SV_StepDirection(actor, tempdir, dist) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//We tried. Run backwards. THAT ought to work...
|
|
||||||
if(turnaround != -1 && SV_StepDirection(actor, turnaround, dist) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Well, we're stuck somehow.
|
|
||||||
actor->v.ideal_yaw = olddir;
|
|
||||||
|
|
||||||
// if a bridge was pulled out from underneath a monster, it may not have
|
|
||||||
// a valid standing position at all.
|
|
||||||
|
|
||||||
if(SV_CheckBottom(actor) == 0) {
|
|
||||||
SV_FixCheckBottom(actor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MoveToOrigin stuff, accd to sdk, and why would it lie.
|
|
||||||
#define MOVE_START_TURN_DIST 64 // when this far away from moveGoal, start turning to face next goal
|
|
||||||
#define MOVE_STUCK_DIST 32 // if a monster can't step this far, it is stuck.
|
|
||||||
#define MOVE_NORMAL 0 // normal move in the direction monster is facing
|
|
||||||
#define MOVE_STRAFE 1 // moves in direction specified, no matter which way monster is facing
|
|
||||||
HLDS_DLLEXPORT void SV_MoveToOrigin_I(edict_t *ent, const vec3_t pflGoal, float dist, int iMoveType) {
|
|
||||||
|
|
||||||
vec3_t var_c_temp;
|
|
||||||
|
|
||||||
|
|
||||||
var_c_temp[0] = pflGoal[0];
|
|
||||||
var_c_temp[1] = pflGoal[1];
|
|
||||||
var_c_temp[2] = pflGoal[2];
|
|
||||||
|
|
||||||
if(ent->v.flags & (FL_FLY | FL_SWIM | FL_ONGROUND)) {
|
|
||||||
if(iMoveType == MOVE_NORMAL) {
|
|
||||||
|
|
||||||
if(SV_StepDirection(ent, ent->v.ideal_yaw, dist) == 0) {
|
|
||||||
SV_NewChaseDir2(ent, var_c_temp, dist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
var_c_temp[0] -= ent->v.origin[0];
|
|
||||||
var_c_temp[1] -= ent->v.origin[1];
|
|
||||||
|
|
||||||
if(ent->v.flags & (FL_FLY | FL_SWIM)) {
|
|
||||||
var_c_temp[2] -= ent->v.origin[2];
|
|
||||||
}
|
|
||||||
else { //If on ground, I guess we just don't worry about the third axis. Sorta makes sense.
|
|
||||||
var_c_temp[2] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorNormalize(var_c_temp);
|
|
||||||
VectorScale(var_c_temp, dist, var_c_temp);
|
|
||||||
SV_FlyDirection(ent, var_c_temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*** Traces ***/
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_SetGlobalTrace
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: Functions that are about to hand themselves over to mods.
|
|
||||||
//
|
|
||||||
// Copies variables to a global variable structure so that a mod
|
|
||||||
// knows what it is dealing with.
|
|
||||||
*/
|
|
||||||
void SV_SetGlobalTrace(trace_t * tr) {
|
|
||||||
|
|
||||||
gGlobalVariables.trace_allsolid = tr->allsolid;
|
|
||||||
gGlobalVariables.trace_startsolid = tr->startsolid;
|
|
||||||
gGlobalVariables.trace_fraction = tr->fraction;
|
|
||||||
gGlobalVariables.trace_inopen = tr->inopen;
|
|
||||||
gGlobalVariables.trace_inwater = tr->inwater;
|
|
||||||
|
|
||||||
gGlobalVariables.trace_endpos[0] = tr->endpos[0];
|
|
||||||
gGlobalVariables.trace_endpos[1] = tr->endpos[1];
|
|
||||||
gGlobalVariables.trace_endpos[2] = tr->endpos[2];
|
|
||||||
gGlobalVariables.trace_plane_normal[0] = tr->plane.normal[0];
|
|
||||||
gGlobalVariables.trace_plane_normal[1] = tr->plane.normal[1];
|
|
||||||
gGlobalVariables.trace_plane_normal[2] = tr->plane.normal[2];
|
|
||||||
gGlobalVariables.trace_plane_dist = tr->plane.dist;
|
|
||||||
|
|
||||||
if(tr->pHit == NULL) {
|
|
||||||
gGlobalVariables.trace_ent = global_sv.edicts;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gGlobalVariables.trace_ent = tr->pHit;
|
|
||||||
}
|
|
||||||
|
|
||||||
gGlobalVariables.trace_hitgroup = tr->hitgroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_Trace_Toss
|
|
||||||
// LOCATION: sv_phys.c
|
|
||||||
// PATH: PF_TraceToss_Shared
|
|
||||||
//
|
|
||||||
// Say I throw a grenade. Where will it go? This function finds out by
|
|
||||||
// simulating ten seconds' worth of frames.
|
|
||||||
*/
|
|
||||||
trace_t * SV_Trace_Toss(trace_t * Outgoing_Trace, edict_t *tossent, edict_t *ignore) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
vec3_t var_378_end;
|
|
||||||
vec3_t var_36C_move;
|
|
||||||
trace_t var_360_trace;
|
|
||||||
edict_t var_324_TempEdict;
|
|
||||||
edict_t * var_328_TempEdictPtr;
|
|
||||||
double var_380_host_frametime;
|
|
||||||
|
|
||||||
var_380_host_frametime = host_frametime;
|
|
||||||
host_frametime = .05;
|
|
||||||
|
|
||||||
Q_memcpy(&var_324_TempEdict, tossent, sizeof(edict_t));
|
|
||||||
|
|
||||||
var_328_TempEdictPtr = &var_324_TempEdict;
|
|
||||||
|
|
||||||
// while(1) //a sanity check to avoid tracing more than ten seconds was present in QW, I think it's a good idea. This may need to be adjusted to account for the alterable frametimes.
|
|
||||||
for (i = 0; i < 200; i++)
|
|
||||||
{
|
|
||||||
SV_CheckVelocity(var_328_TempEdictPtr);
|
|
||||||
SV_AddGravity(var_328_TempEdictPtr);
|
|
||||||
VectorMA(var_328_TempEdictPtr->v.angles, host_frametime, var_328_TempEdictPtr->v.avelocity, var_328_TempEdictPtr->v.angles);
|
|
||||||
VectorScale(var_328_TempEdictPtr->v.velocity, host_frametime, var_36C_move);
|
|
||||||
VectorAdd(var_328_TempEdictPtr->v.origin, var_36C_move, var_378_end);
|
|
||||||
|
|
||||||
var_360_trace = SV_Move(var_328_TempEdictPtr->v.origin, var_328_TempEdictPtr->v.mins, var_328_TempEdictPtr->v.maxs, var_378_end, 0, var_328_TempEdictPtr, 0);
|
|
||||||
VectorCopy(var_360_trace.endpos, var_328_TempEdictPtr->v.origin);
|
|
||||||
|
|
||||||
if(var_360_trace.pHit != NULL && var_360_trace.pHit != ignore) { break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
host_frametime = var_380_host_frametime;
|
|
||||||
Q_memcpy(Outgoing_Trace, &var_360_trace, sizeof(trace_t));
|
|
||||||
return(Outgoing_Trace);
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
/* The function SV_Move, and many of the functions directly underneath it.
|
|
||||||
// Sort've sits between sv_phys and world, though sv_move is called in many
|
|
||||||
// places.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_MOVE_HEADER
|
|
||||||
#define OSHLDS_SV_MOVE_HEADER
|
|
||||||
|
|
||||||
#include "edict.h"
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "Mod.h"
|
|
||||||
|
|
||||||
|
|
||||||
//structs
|
|
||||||
typedef struct trace_s { //sizeof 0x38
|
|
||||||
|
|
||||||
qboolean allsolid; //if true, plane is not valid
|
|
||||||
qboolean startsolid; // if true, the initial point was in a solid area
|
|
||||||
qboolean inopen, inwater;
|
|
||||||
float fraction; // time completed, 1.0 = didn't hit anything
|
|
||||||
vec3_t endpos; // final position
|
|
||||||
plane_t plane; // 20 surface normal at impact. Not its own struct in HL.
|
|
||||||
edict_t *pHit; // 30, entity the surface is on
|
|
||||||
int hitgroup; // 0 == generic, non zero is specific body part
|
|
||||||
} trace_t;
|
|
||||||
typedef struct TraceResult_s {
|
|
||||||
|
|
||||||
int fAllSolid;
|
|
||||||
int fStartSolid;
|
|
||||||
int fInOpen;
|
|
||||||
int fInWater;
|
|
||||||
float flFraction;
|
|
||||||
vec3_t vecEndPos;
|
|
||||||
float flPlaneDist;
|
|
||||||
vec3_t vecPlaneNormal;
|
|
||||||
edict_t *pHit;
|
|
||||||
int iHitgroup;
|
|
||||||
} TraceResult_t;
|
|
||||||
typedef struct moveclip_s { //sizeof(0x84)
|
|
||||||
|
|
||||||
vec3_t boxmins; //enclose the test object along entire move
|
|
||||||
vec3_t boxmaxs; //0c
|
|
||||||
vec_t * mins; // size of the moving object
|
|
||||||
vec_t * maxs; //1c
|
|
||||||
vec3_t mins2; // size when clipping against mosnters
|
|
||||||
vec3_t maxs2; //2c
|
|
||||||
vec_t * start; //38
|
|
||||||
vec_t * end; //3c
|
|
||||||
trace_t trace; //40 confirmed
|
|
||||||
|
|
||||||
short int type1; //78
|
|
||||||
short int type2; //7A
|
|
||||||
edict_t *passedict; //7c
|
|
||||||
int hullnum; //80
|
|
||||||
} moveclip_t;
|
|
||||||
|
|
||||||
|
|
||||||
trace_t SV_Move(vec3_t, vec3_t, vec3_t, vec3_t, int, edict_t *, int);
|
|
||||||
trace_t * SV_ClipMoveToEntity(trace_t *, edict_t *, vec3_t, vec3_t, vec3_t, vec3_t);
|
|
||||||
|
|
||||||
void PF_WaterMove(edict_t *);
|
|
||||||
qboolean SV_movestep(edict_t *, vec3_t, qboolean);
|
|
||||||
qboolean SV_movetest(edict_t *, vec3_t, qboolean);
|
|
||||||
void SV_SetGlobalTrace(trace_t *);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void SV_MoveToOrigin_I(edict_t *, const vec3_t, float, int);
|
|
||||||
trace_t * SV_Trace_Toss(trace_t *, edict_t *, edict_t *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,58 +0,0 @@
|
|||||||
/* SV_Phys handles the specially named physics functions, and also handles
|
|
||||||
// movevars. The reason for the merger is that the physics functions
|
|
||||||
// use a couple of the movevars. This layer sits above sv_move().
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_PHYSICS_HEADER
|
|
||||||
#define OSHLDS_SV_PHYSICS_HEADER
|
|
||||||
|
|
||||||
#include "delta.h"
|
|
||||||
#include "edict.h"
|
|
||||||
#include "sizebuf.h"
|
|
||||||
|
|
||||||
void SV_Movevars_Init();
|
|
||||||
|
|
||||||
void SV_SetMoveVars();
|
|
||||||
void SV_WriteMovevarsToClient(sizebuf_t *);
|
|
||||||
void SV_QueryMovevarsChanged();
|
|
||||||
|
|
||||||
void SV_CheckVelocity(edict_t *);
|
|
||||||
void SV_AddGravity(edict_t *);
|
|
||||||
qboolean SV_CheckBottom(edict_t *);
|
|
||||||
|
|
||||||
void SV_Physics();
|
|
||||||
void SV_RunCmd(usercmd_t *, unsigned int);
|
|
||||||
|
|
||||||
typedef struct movevars_s { //SDK, HL has more of these than QW
|
|
||||||
|
|
||||||
float gravity; // Gravity for map
|
|
||||||
float stopspeed; // Deceleration when not moving
|
|
||||||
float maxspeed; // Max allowed speed
|
|
||||||
float spectatormaxspeed;
|
|
||||||
float accelerate; // Acceleration factor
|
|
||||||
float airaccelerate; // Same for when in open air
|
|
||||||
float wateraccelerate; // Same for when in water
|
|
||||||
float friction;
|
|
||||||
float edgefriction; // Extra friction near dropofs
|
|
||||||
float waterfriction; // Less in water
|
|
||||||
float entgravity; // 1.0
|
|
||||||
float bounce; // Wall bounce value. 1.0
|
|
||||||
float stepsize; // sv_stepsize;
|
|
||||||
float maxvelocity; // maximum server velocity.
|
|
||||||
float zmax; // Max z-buffer range (for GL)
|
|
||||||
float waveHeight; // Water wave height (for GL)
|
|
||||||
qboolean footsteps; //0x40 Play footstep sounds
|
|
||||||
char skyName[32]; // Name of the sky map
|
|
||||||
float rollangle; //0x64
|
|
||||||
float rollspeed;
|
|
||||||
float skycolor_r; // Sky color
|
|
||||||
float skycolor_g; //
|
|
||||||
float skycolor_b; //
|
|
||||||
float skyvec_x; // Sky vector
|
|
||||||
float skyvec_y; //
|
|
||||||
float skyvec_z; //
|
|
||||||
} movevars_t;
|
|
||||||
|
|
||||||
extern movevars_t movevars;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,30 +0,0 @@
|
|||||||
/* SV_Packet stuff, sitting above the NET stuff. This isn't nearly as bad
|
|
||||||
// as sv_hlds was, but it's corrently the most unorganized file around.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_PACKET_HEADER
|
|
||||||
#define OSHLDS_SV_PACKET_HEADER
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "edict.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "report.h"
|
|
||||||
|
|
||||||
void SV_ReadPackets();
|
|
||||||
|
|
||||||
//outgoing
|
|
||||||
void SV_SendBan();
|
|
||||||
void SV_BuildReconnect(sizebuf_t *);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void ClientPrintf(edict_t *, PRINT_TYPE, const char *);
|
|
||||||
void SV_SendClientMessages();
|
|
||||||
void SV_StartParticle(const vec3_t, const vec3_t, int, int);
|
|
||||||
void SV_CreateBaseline();
|
|
||||||
void SV_SendUserReg(sizebuf_t *);
|
|
||||||
void SV_Packet_Init();
|
|
||||||
void SV_WriteSpawn(sizebuf_t *);
|
|
||||||
void SV_SendServerinfo(sizebuf_t *, client_t *);
|
|
||||||
|
|
||||||
void SV_Packet_Init();
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,19 +0,0 @@
|
|||||||
/* Connectionless packets go here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_PACKET_CONNECTIONLESS_HEADER
|
|
||||||
#define OSHLDS_SV_PACKET_CONNECTIONLESS_HEADER
|
|
||||||
|
|
||||||
#include "NET.h"
|
|
||||||
|
|
||||||
int SV_GetFragmentSize(client_t *);
|
|
||||||
char * SV_GetClientIDString(client_t *);
|
|
||||||
void SV_ConnectionlessPacket();
|
|
||||||
|
|
||||||
void SV_ResetModInfo();
|
|
||||||
void SV_SetUsingMod();
|
|
||||||
void SV_LoadModDataFromFile(const char *, const char *);
|
|
||||||
|
|
||||||
void SV_Packet_Connectionless_Init();
|
|
||||||
void SV_ConnectionlessPacket_Init();
|
|
||||||
#endif
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
#include "SV_rcon.h"
|
|
||||||
#include "cmd.h"
|
|
||||||
#include "cvar.h"
|
|
||||||
#include "crc.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "SV_chals.h"
|
|
||||||
#include "report.h"
|
|
||||||
|
|
||||||
#include "inetaton.h"
|
|
||||||
#include "libcprops-0.1.8/avl.h"
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
/*** GLOBALS ***/
|
|
||||||
//vars
|
|
||||||
static cvar_t cvar_sv_password = { "sv_password", "", (FCVAR_SERVER | FCVAR_PROTECTED), 0, NULL };
|
|
||||||
|
|
||||||
static cvar_t cvar_rcon_password = { "rcon_password", "", FCVAR_NONE, 0, NULL };
|
|
||||||
static cvar_t cvar_sv_rcon_minfailures = { "sv_rcon_minfailures", "5", FCVAR_NONE, 5.0, NULL };
|
|
||||||
static cvar_t cvar_sv_rcon_maxfailures = { "sv_rcon_maxfailures", "10", FCVAR_NONE, 10.0, NULL };
|
|
||||||
static cvar_t cvar_sv_rcon_minfailuretime = { "sv_rcon_minfailuretime", "30", FCVAR_NONE, 30.0, NULL };
|
|
||||||
static cvar_t cvar_sv_rcon_banpenalty = { "sv_rcon_banpenalty", "30", FCVAR_NONE, 30.0, NULL };
|
|
||||||
|
|
||||||
static qboolean use_rcon = 0;
|
|
||||||
static byte rcon_password[16];
|
|
||||||
|
|
||||||
/*** FUNCTIONS ***/
|
|
||||||
|
|
||||||
void SV_Rcon_ChangePassword_f() {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
const char * ptr;
|
|
||||||
MD5Context_t md5hash;
|
|
||||||
|
|
||||||
|
|
||||||
if(global_cmd_source != cmd_SERVER) { return; }
|
|
||||||
|
|
||||||
if(Cmd_Argc() != 2) {
|
|
||||||
|
|
||||||
Con_Printf("rcon is currently %sabled.\n", (use_rcon == 0) ? "dis" : "en");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = Cmd_Argv(1);
|
|
||||||
i = strlen(ptr);
|
|
||||||
if(i < 1) {
|
|
||||||
|
|
||||||
use_rcon = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//This might be a good place to berate people who choose bad passwords.
|
|
||||||
|
|
||||||
//hash it
|
|
||||||
memset(&md5hash, 0, sizeof(md5hash));
|
|
||||||
MD5Init(&md5hash);
|
|
||||||
MD5Update(&md5hash, ptr, i);
|
|
||||||
MD5Final(rcon_password, &md5hash);
|
|
||||||
|
|
||||||
use_rcon = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SV_Rcon_Validate() {
|
|
||||||
|
|
||||||
MD5Context_t md5hash;
|
|
||||||
byte temp[16];
|
|
||||||
const char * ptr;
|
|
||||||
|
|
||||||
|
|
||||||
//First off, check challenges. None of this matters if we can't verify the address.
|
|
||||||
if(SV_CheckChallenge(&global_net_from, Q_atoi(Cmd_Argv(1))) == 0) {
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Now check the password.
|
|
||||||
ptr = Cmd_Argv(2);
|
|
||||||
memset(&md5hash, 0, sizeof(md5hash));
|
|
||||||
|
|
||||||
MD5Init(&md5hash);
|
|
||||||
MD5Update(&md5hash, ptr, strlen(ptr));
|
|
||||||
MD5Final(temp, &md5hash);
|
|
||||||
|
|
||||||
if(memcmp(temp, rcon_password, sizeof(rcon_password)) == 0) { //Good boy.
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//If we are here, password matching failed. I'm tired. Screw this.
|
|
||||||
//I'll add the ban checking code later.
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SV_Rcon() {
|
|
||||||
|
|
||||||
unsigned int i, len, total;
|
|
||||||
char temp[0x400];
|
|
||||||
char * ptr;
|
|
||||||
|
|
||||||
|
|
||||||
if(use_rcon == 0) { return; } //If we do this check later on, we can conceal the fact that we DO have an rcon password. Is that worth it?
|
|
||||||
|
|
||||||
total = Cmd_Argc();
|
|
||||||
if(total < 4) { return; } //not enough args to be valid.
|
|
||||||
|
|
||||||
if(SV_Rcon_Validate() == 0) { return; } //Failed. The validator takes care of bans already.
|
|
||||||
|
|
||||||
|
|
||||||
//An example: rcon <challence> <password> <command>. The first three don't matter now.
|
|
||||||
|
|
||||||
temp[0] = '\0';
|
|
||||||
ptr = temp;
|
|
||||||
len = 0;
|
|
||||||
|
|
||||||
for(i = 3; i < total; i++) {
|
|
||||||
|
|
||||||
len += Q_snprintf(ptr, sizeof(temp) - (len + 1), "%s ", Cmd_Argv(i));
|
|
||||||
if(sizeof(temp)-1 < len) {
|
|
||||||
temp[sizeof(temp)-1] = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ptr = len + temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cmd_ExecuteString(temp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SV_RconInit() {
|
|
||||||
|
|
||||||
Cvar_RegisterVariable(&cvar_rcon_password);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_rcon_minfailures);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_rcon_maxfailures);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_rcon_minfailuretime);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_rcon_banpenalty);
|
|
||||||
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_password);
|
|
||||||
|
|
||||||
Cmd_AddCommand("rcon_password", SV_Rcon_ChangePassword_f);
|
|
||||||
}
|
|
||||||
void SV_RconShutdown() {
|
|
||||||
|
|
||||||
//I realize that, since the password is transmitted in plain text, that
|
|
||||||
//zeroing out the hash to make further recovery difficult is pretty
|
|
||||||
//pointless, as is perhaps using a hash altogether. But it makes me
|
|
||||||
//sleep better at night.
|
|
||||||
|
|
||||||
//The opimizer shouldn't interfere.
|
|
||||||
Q_memset(rcon_password, 0, sizeof(rcon_password));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//regular passwords
|
|
||||||
int ServerIsPassworded() {
|
|
||||||
|
|
||||||
const char * c;
|
|
||||||
|
|
||||||
c = cvar_sv_password.string;
|
|
||||||
if(c[0] == '\0' || Q_memcmp(c, "none", sizeof("none")) == 0) { return(0); }
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
int CheckPassword(const char * pass) {
|
|
||||||
|
|
||||||
const char * c;
|
|
||||||
|
|
||||||
c = cvar_sv_password.string;
|
|
||||||
if(c[0] == '\0' || Q_memcmp(c, "none", sizeof("none")) == 0 || Q_strcmp(pass, c) == 0) { return(1); }
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/* The rcon is, well, a remote password protected console. Aside from a
|
|
||||||
// challenge request to verify IPs, the basic setuo is this: we get one
|
|
||||||
// packet in the form of 0xFFFFFFFF "rcon" <challenge> <password> <command>.
|
|
||||||
//
|
|
||||||
// The astute will probably observe that this simple plain text transmission
|
|
||||||
// of the PASSWORD is very BAD. However, there's nothing I can do about
|
|
||||||
// that until the client is ready (though I CAN add a more secure version
|
|
||||||
// if admins are willing to use a third program).
|
|
||||||
//
|
|
||||||
// Unfortunately the output will be to the console, not the user.
|
|
||||||
// The console will need a bit of an overhaul before we can redirect
|
|
||||||
// the output. Command and cvar levels are also of interest.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_RCON_HEADER
|
|
||||||
#define OSHLDS_SV_RCON_HEADER
|
|
||||||
|
|
||||||
|
|
||||||
void SV_RconInit();
|
|
||||||
void SV_RconShutdown();
|
|
||||||
void SV_Rcon();
|
|
||||||
|
|
||||||
//
|
|
||||||
int ServerIsPassworded();
|
|
||||||
int CheckPassword(const char *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,971 +0,0 @@
|
|||||||
#include "SV_user.h"
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include "Modding.h"
|
|
||||||
#include "sys.h"
|
|
||||||
#include "VecMath.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*** STRUCTS ***/
|
|
||||||
typedef struct temp_move_s { //0x54, has now been reordered since it seems to be unique.
|
|
||||||
|
|
||||||
int IsActive; //00, this entity is being processed.
|
|
||||||
int IsMoving; //04 destination and origin are not the same.
|
|
||||||
int FirstIteration; //54
|
|
||||||
int DoNotInterpolate; //44
|
|
||||||
|
|
||||||
vec3_t Mins; //2C
|
|
||||||
vec3_t Maxs; //38
|
|
||||||
vec3_t CurrentPosition; //20
|
|
||||||
vec3_t OldLocation; //14
|
|
||||||
vec3_t NewLocation; //08
|
|
||||||
vec3_t FinalVectors; //48
|
|
||||||
} temp_move_t;
|
|
||||||
|
|
||||||
|
|
||||||
/*** GLOBALS ***/
|
|
||||||
|
|
||||||
unsigned int SV_UPDATE_MASK = 7;
|
|
||||||
unsigned int SV_UPDATE_BACKUP = 8;
|
|
||||||
|
|
||||||
static int nofind = 0;
|
|
||||||
static temp_move_t truepositions[32]; //That'll need to be dynamic. Can't have 600 players elsewise.
|
|
||||||
|
|
||||||
static cvar_t cvar_sv_maxrate = { "sv_maxrate", "0", FCVAR_SERVER, 0.0, NULL };
|
|
||||||
static cvar_t cvar_sv_minrate = { "sv_minrate", "0", FCVAR_SERVER, 0.0, NULL };
|
|
||||||
static cvar_t cvar_sv_maxupdaterate = { "sv_maxupdaterate", "30.0", FCVAR_NONE, 30.0, NULL };
|
|
||||||
static cvar_t cvar_sv_minupdaterate = { "sv_minupdaterate", "10.0", FCVAR_NONE, 10.0, NULL };
|
|
||||||
static cvar_t cvar_sv_unlag = { "sv_unlag", "1", FCVAR_NONE, 1.0, NULL };
|
|
||||||
static cvar_t cvar_sv_maxunlag = { "sv_maxunlag", "0.5", FCVAR_NONE, 0.5, NULL };
|
|
||||||
static cvar_t cvar_sv_unlagpush = { "sv_unlagpush", "0.0", FCVAR_NONE, 0.0, NULL };
|
|
||||||
static cvar_t cvar_sv_unlagsamples = { "sv_unlagsamples", "1", FCVAR_NONE, 1.0, NULL };
|
|
||||||
|
|
||||||
/*** FUNCTIONS ***/
|
|
||||||
|
|
||||||
|
|
||||||
//general purpose
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_FindEntInPack
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_RunCmd->SV_SetupMove
|
|
||||||
//
|
|
||||||
// This wee little function simply loops around to find an entity in--
|
|
||||||
// you guessed it--a pack. It's just a 'general' function that only gets
|
|
||||||
// used in this file.
|
|
||||||
*/
|
|
||||||
entity_state_t * SV_FindEntInPack(int index, packet_entities_t * PacksToSearch) {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
|
|
||||||
for(i = 0; i < PacksToSearch->max_entities; i++) {
|
|
||||||
|
|
||||||
if(PacksToSearch->entities[i].number == index) {
|
|
||||||
return(&(PacksToSearch->entities[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_GetTrueOrigin
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_AddLinksToPM_->SV_CopyEdictToPhysent
|
|
||||||
//
|
|
||||||
// This calls upon those trueposition statics in order to properly report
|
|
||||||
// a player's position mid-move or something. There are an awful lot of
|
|
||||||
// abort cases, such as no lag compensation.
|
|
||||||
*/
|
|
||||||
void SV_GetTrueOrigin(int edictnum, vec3_t out_origin) {
|
|
||||||
|
|
||||||
if(global_host_client->cl_lw == 0 || global_host_client->cl_lc == 0 ||
|
|
||||||
(int)cvar_sv_unlag.value == 0 ||
|
|
||||||
global_svs.allocated_client_slots <= 1 ||
|
|
||||||
global_host_client->padding00_used == 0 ||
|
|
||||||
edictnum < 0 || (unsigned)edictnum >= global_svs.allocated_client_slots ||
|
|
||||||
truepositions[edictnum].IsActive == 0 || truepositions[edictnum].IsMoving == 0) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
out_origin[0] = truepositions[edictnum].NewLocation[0];
|
|
||||||
out_origin[1] = truepositions[edictnum].NewLocation[1];
|
|
||||||
out_origin[2] = truepositions[edictnum].NewLocation[2];
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_GetTrueMinMax
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_AddLinksToPM_
|
|
||||||
//
|
|
||||||
// Once more, digs data out of the ststic vars.
|
|
||||||
*/
|
|
||||||
void SV_GetTrueMinMax(int edictnum, float ** out_vecmins, float ** out_vecmaxs) {
|
|
||||||
|
|
||||||
if(global_host_client->cl_lw == 0 || global_host_client->cl_lc == 0 ||
|
|
||||||
(int)cvar_sv_unlag.value == 0 ||
|
|
||||||
global_svs.allocated_client_slots <= 1 ||
|
|
||||||
global_host_client->padding00_used == 0 ||
|
|
||||||
edictnum < 0 || (unsigned)edictnum >= global_svs.allocated_client_slots ||
|
|
||||||
truepositions[edictnum].IsActive == 0 || truepositions[edictnum].IsMoving == 0) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_vecmins = truepositions[edictnum].Mins;
|
|
||||||
*out_vecmaxs = truepositions[edictnum].Maxs;
|
|
||||||
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_CopyEdictToPhysent
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_AddLinksToPM_
|
|
||||||
//
|
|
||||||
// This appears to be a struct converter. Probably doesn't belong here, but
|
|
||||||
// things it calls are here, and it has to go somewhere.
|
|
||||||
*/
|
|
||||||
void SV_CopyEdictToPhysent(physent_t * out_physent, int edictnum, edict_t * in_ent) {
|
|
||||||
|
|
||||||
model_t * ptr;
|
|
||||||
|
|
||||||
|
|
||||||
out_physent->info = edictnum;
|
|
||||||
out_physent->origin[0] = in_ent->v.origin[0];
|
|
||||||
out_physent->origin[1] = in_ent->v.origin[1];
|
|
||||||
out_physent->origin[2] = in_ent->v.origin[2];
|
|
||||||
|
|
||||||
if(edictnum <= 0 || (unsigned)edictnum > global_svs.allocated_client_slots) {
|
|
||||||
|
|
||||||
out_physent->player = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
SV_GetTrueOrigin(edictnum-1, out_physent->origin);
|
|
||||||
out_physent->player = edictnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
out_physent->angles[0] = in_ent->v.angles[0];
|
|
||||||
out_physent->angles[1] = in_ent->v.angles[1];
|
|
||||||
out_physent->angles[2] = in_ent->v.angles[2];
|
|
||||||
out_physent->studiomodel = NULL;
|
|
||||||
out_physent->rendermode = in_ent->v.rendermode;
|
|
||||||
|
|
||||||
switch(in_ent->v.solid) {
|
|
||||||
|
|
||||||
case SOLID_NOT:
|
|
||||||
|
|
||||||
if(in_ent->v.modelindex == 0) {
|
|
||||||
out_physent->model = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
out_physent->model = global_sv.models[in_ent->v.modelindex];
|
|
||||||
Q_strncpy(out_physent->name, out_physent->model->name, 0x1F);
|
|
||||||
out_physent->name[0x1F] = '\0';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SOLID_BBOX:
|
|
||||||
|
|
||||||
out_physent->model = NULL;
|
|
||||||
if(in_ent->v.modelindex == 0) {
|
|
||||||
ptr = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptr = global_sv.models[in_ent->v.modelindex];
|
|
||||||
}
|
|
||||||
if(ptr != NULL) { //This block simplified.
|
|
||||||
if((ptr->flags & 0x200) != 0) {
|
|
||||||
|
|
||||||
out_physent->studiomodel = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_strncpy(out_physent->name, ptr->name, 0x1F);
|
|
||||||
out_physent->name[0x1F] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
out_physent->mins[0] = in_ent->v.mins[0];
|
|
||||||
out_physent->mins[1] = in_ent->v.mins[1];
|
|
||||||
out_physent->mins[2] = in_ent->v.mins[2];
|
|
||||||
out_physent->maxs[0] = in_ent->v.maxs[0];
|
|
||||||
out_physent->maxs[1] = in_ent->v.maxs[1];
|
|
||||||
out_physent->maxs[2] = in_ent->v.maxs[2];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SOLID_BSP:
|
|
||||||
|
|
||||||
out_physent->model = global_sv.models[in_ent->v.modelindex];
|
|
||||||
Q_strncpy(out_physent->name, out_physent->model->name, 0x1F);
|
|
||||||
out_physent->name[0x1F] = '\0';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
out_physent->model = NULL;
|
|
||||||
|
|
||||||
out_physent->mins[0] = in_ent->v.mins[0];
|
|
||||||
out_physent->mins[1] = in_ent->v.mins[1];
|
|
||||||
out_physent->mins[2] = in_ent->v.mins[2];
|
|
||||||
out_physent->maxs[0] = in_ent->v.maxs[0];
|
|
||||||
out_physent->maxs[1] = in_ent->v.maxs[1];
|
|
||||||
out_physent->maxs[2] = in_ent->v.maxs[2];
|
|
||||||
|
|
||||||
if(in_ent->v.classname == 0) {
|
|
||||||
Q_strcpy(out_physent->name, "?");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Q_strncpy(out_physent->name, global_pr_strings + in_ent->v.classname, 0x1F);
|
|
||||||
out_physent->name[0x1F] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//No more branches from this point.
|
|
||||||
out_physent->solid = in_ent->v.solid;
|
|
||||||
out_physent->skin = in_ent->v.skin;
|
|
||||||
out_physent->frame = in_ent->v.frame;
|
|
||||||
out_physent->sequence = in_ent->v.sequence;
|
|
||||||
|
|
||||||
Q_memcpy(out_physent->controller, in_ent->v.controller, 4);
|
|
||||||
Q_memcpy(out_physent->blending, in_ent->v.blending, 2);
|
|
||||||
|
|
||||||
out_physent->movetype = in_ent->v.movetype;
|
|
||||||
out_physent->takedamage = 0;
|
|
||||||
out_physent->blooddecal = 0;
|
|
||||||
|
|
||||||
out_physent->iuser1 = in_ent->v.iuser1;
|
|
||||||
out_physent->iuser2 = in_ent->v.iuser2;
|
|
||||||
out_physent->iuser3 = in_ent->v.iuser3;
|
|
||||||
out_physent->iuser4 = in_ent->v.iuser4;
|
|
||||||
out_physent->fuser1 = in_ent->v.fuser1;
|
|
||||||
out_physent->fuser2 = in_ent->v.fuser2;
|
|
||||||
out_physent->fuser3 = in_ent->v.fuser3;
|
|
||||||
out_physent->fuser4 = in_ent->v.fuser4;
|
|
||||||
out_physent->vuser1[0] = in_ent->v.vuser1[0];
|
|
||||||
out_physent->vuser1[1] = in_ent->v.vuser1[1];
|
|
||||||
out_physent->vuser1[2] = in_ent->v.vuser1[2];
|
|
||||||
out_physent->vuser2[0] = in_ent->v.vuser2[0];
|
|
||||||
out_physent->vuser2[1] = in_ent->v.vuser2[1];
|
|
||||||
out_physent->vuser2[2] = in_ent->v.vuser2[2];
|
|
||||||
out_physent->vuser3[0] = in_ent->v.vuser3[0];
|
|
||||||
out_physent->vuser3[1] = in_ent->v.vuser3[1];
|
|
||||||
out_physent->vuser3[2] = in_ent->v.vuser3[2];
|
|
||||||
out_physent->vuser4[0] = in_ent->v.vuser4[0];
|
|
||||||
out_physent->vuser4[1] = in_ent->v.vuser4[1];
|
|
||||||
out_physent->vuser4[2] = in_ent->v.vuser4[2];
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SetMinMaxSize
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: lots
|
|
||||||
//
|
|
||||||
// Sets the min, max, and size of an edict. The min and max is given;
|
|
||||||
// the size isn't too hard to work out.
|
|
||||||
// The fourth argument triggers an extra long branch in the function.
|
|
||||||
// For some reason, it's assigned a value right before it's used in a
|
|
||||||
// comparison, guaranteeing the code won't ever be reached.
|
|
||||||
*/
|
|
||||||
void SetMinMaxSize(edict_t * ed, const vec3_t mins, const vec3_t maxs, int ChangedByMod) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
for(i = 0; i < 3; i++) {
|
|
||||||
if(mins[i] > maxs[i]) {
|
|
||||||
Sys_Error("%s: mismatched mins/maxs.", __FUNCTION__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//There's a very large unreachable block of code here
|
|
||||||
ed->v.mins[0] = mins[0];
|
|
||||||
ed->v.mins[1] = mins[1];
|
|
||||||
ed->v.mins[2] = mins[2];
|
|
||||||
ed->v.maxs[0] = maxs[0];
|
|
||||||
ed->v.maxs[1] = maxs[1];
|
|
||||||
ed->v.maxs[2] = maxs[2];
|
|
||||||
ed->v.size[0] = maxs[0] - mins[0];
|
|
||||||
ed->v.size[1] = maxs[1] - mins[1];
|
|
||||||
ed->v.size[2] = maxs[2] - mins[2];
|
|
||||||
|
|
||||||
SV_LinkEdict(ed, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//userinfo based
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_CheckRate/SV_CheckUpdateRate
|
|
||||||
// PATH: SV_ExtractFromUserinfo
|
|
||||||
//
|
|
||||||
// Simply make sure the value given is within acceptable limits.
|
|
||||||
*/
|
|
||||||
void SV_CheckRate(client_t *cl) {
|
|
||||||
|
|
||||||
float temp;
|
|
||||||
|
|
||||||
|
|
||||||
temp = cvar_sv_maxrate.value;
|
|
||||||
if(temp > 0 && cl->netchan1C.rate > temp) {
|
|
||||||
cl->netchan1C.rate = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = cvar_sv_minrate.value;
|
|
||||||
if(temp > 0 && cl->netchan1C.rate < temp) {
|
|
||||||
cl->netchan1C.rate = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void SV_CheckUpdateRate(double * rate) {
|
|
||||||
|
|
||||||
float temp;
|
|
||||||
|
|
||||||
|
|
||||||
if((*rate) == 0) {
|
|
||||||
*rate = (1.0 / 20.0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
temp = cvar_sv_maxupdaterate.value;
|
|
||||||
if(temp != 0) {
|
|
||||||
if(temp <= 0.001) {
|
|
||||||
Cvar_DirectSetValue(&cvar_sv_maxupdaterate, 30.0);
|
|
||||||
temp = 30;
|
|
||||||
}
|
|
||||||
if(*rate < 1.0 / temp) {
|
|
||||||
*rate = 1.0 / temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = cvar_sv_minupdaterate.value;
|
|
||||||
if(temp != 0) {
|
|
||||||
if(temp <= 0.001) {
|
|
||||||
Cvar_DirectSetValue(&cvar_sv_minupdaterate, 10.0);
|
|
||||||
temp = 10;
|
|
||||||
}
|
|
||||||
if(*rate > 1.0 / temp) {
|
|
||||||
*rate = 1.0 / temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: TrimSpace
|
|
||||||
// PATH: SV_ExtractFromUserinfo
|
|
||||||
//
|
|
||||||
// Yet another boring text cleaner. Probably not unbeatable,
|
|
||||||
// certainly not special.
|
|
||||||
*/
|
|
||||||
void TrimSpace(char * in, char * out) {
|
|
||||||
|
|
||||||
char * maxlen;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
//So what are the rules here? Near as I can tell, the rules are 'no
|
|
||||||
//whitespace before or after the name' and assumably 'all must be printable'
|
|
||||||
while(isgraph(*in) == 0) { //skip whitespace
|
|
||||||
|
|
||||||
if(*in == '\0') { //Uh oh, an invalid name. I wonder if we could screw attackers here...
|
|
||||||
*out = '\0';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
in++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//We know there's at least one printable character in this string now.
|
|
||||||
maxlen = out + strlen(out) - 1;
|
|
||||||
while(isgraph(*maxlen) == 0) {
|
|
||||||
maxlen--;
|
|
||||||
}
|
|
||||||
i = maxlen - out; //number of chars
|
|
||||||
|
|
||||||
//copy it. This WAS a memcpy, but I want to make sure non-prints are hit, and I'm too lazy to see if com_arg does that.
|
|
||||||
while(i >= 0) {
|
|
||||||
if(isprint(*in)) { *out = *in; out++; }
|
|
||||||
in++;
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out = '\0';
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_ExtractFromUserinfo
|
|
||||||
// LOCATION: sv_main.c
|
|
||||||
// PATH: SV_UpdateToReliableMessages, PF_CreateFakeClient_I, SV_ConnectClient
|
|
||||||
//
|
|
||||||
// To quote QW: Pull specific info from a newly changed userinfo string
|
|
||||||
// into a more C freindly form. I take it that means text processing.
|
|
||||||
//
|
|
||||||
// This function looks to be responsible for CS-DOS. I blame bad
|
|
||||||
// design, so the problem's not that easily solved.
|
|
||||||
*/
|
|
||||||
void SV_ExtractFromUserinfo(client_t *cl) {
|
|
||||||
|
|
||||||
const char * val;
|
|
||||||
unsigned int i, j;
|
|
||||||
client_t * client;
|
|
||||||
int dupc;
|
|
||||||
char var_34_charbuf1[0x20];
|
|
||||||
char var_54_charbuf2[0x20];
|
|
||||||
|
|
||||||
|
|
||||||
dupc = 1;
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "name");
|
|
||||||
Q_strncpy(var_34_charbuf1, val, sizeof(var_34_charbuf1)-1);
|
|
||||||
var_34_charbuf1[sizeof(var_34_charbuf1)-1] = '\0';
|
|
||||||
Q_strcpy(var_54_charbuf2, var_34_charbuf1);
|
|
||||||
TrimSpace(var_54_charbuf2, var_34_charbuf1);
|
|
||||||
|
|
||||||
if(/*var_34_charbuf1[0] == '\0' ||*/ Q_strcasecmp(var_34_charbuf1, "console") == 0) {
|
|
||||||
|
|
||||||
//IIRC, wasn't this responsible for an infinite loop if the user used the name ""?
|
|
||||||
Info_SetValueForKey(cl->InfoKeyBuffer, "name", "unnamed", 0x100);
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "name");
|
|
||||||
}
|
|
||||||
else if(Q_strcmp(var_34_charbuf1, val) != 0) { //we had to truncate
|
|
||||||
|
|
||||||
Info_SetValueForKey(cl->InfoKeyBuffer, "name", var_34_charbuf1, 0x100);
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "name");
|
|
||||||
}
|
|
||||||
|
|
||||||
// check to see if another user by the same name exists
|
|
||||||
while(1) {
|
|
||||||
for(i = 0, client = global_svs.clients; i < global_svs.allocated_client_slots; i++, client++) {
|
|
||||||
|
|
||||||
if(client == cl || client->padding00_used == 0 || client->padding04 == 0) { continue; }
|
|
||||||
if(Q_strcasecmp(client->PlayerName, val) == 0) { break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i != global_svs.allocated_client_slots) { // dup name
|
|
||||||
|
|
||||||
//This is crap, but I'm tired. I'll properly ban stick attackers later.
|
|
||||||
/* Based on QW< it should be safe to just do the HL equiv of
|
|
||||||
SV_BroadcastTPrintf (PRINT_HIGH, STL_CLIENTKICKEDNAMESPAM, cl->name);
|
|
||||||
SV_ClientTPrintf (cl, PRINT_HIGH, STL_YOUWEREKICKEDNAMESPAM);
|
|
||||||
SV_DropClient (cl);
|
|
||||||
return;
|
|
||||||
// on offendors.
|
|
||||||
*/
|
|
||||||
j = strlen(var_34_charbuf1);
|
|
||||||
if(j > sizeof(var_34_charbuf1)-4) { j = sizeof(var_34_charbuf1)-4; }
|
|
||||||
var_34_charbuf1[j] = '(';
|
|
||||||
j += sprintf(var_34_charbuf1+j, "%u", dupc++) + 1;
|
|
||||||
var_34_charbuf1[j] = ')';
|
|
||||||
var_34_charbuf1[j+1] = '\0';
|
|
||||||
|
|
||||||
Info_SetValueForKey(cl->InfoKeyBuffer, "name", var_34_charbuf1, 0x100);
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "name");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gEntityInterface.pfnClientUserInfoChanged(cl->padding4A84, cl->InfoKeyBuffer); //50
|
|
||||||
strcpy(cl->PlayerName, var_34_charbuf1);
|
|
||||||
|
|
||||||
//whew
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "rate");
|
|
||||||
if(val[0] != '\0') {
|
|
||||||
|
|
||||||
i = Q_atoi(val);
|
|
||||||
if(i < 999) { i = 999; }
|
|
||||||
else if(i > 20000) { i = 20000; }
|
|
||||||
|
|
||||||
cl->netchan1C.rate = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "topcolor");
|
|
||||||
if(val[0] != '\0') {
|
|
||||||
cl->topcolor = Q_atoi(val);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Con_Printf("%s: topcolor unchanged for %s.\n", __FUNCTION__, cl->PlayerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "bottomcolor");
|
|
||||||
if(val[0] != '\0') {
|
|
||||||
cl->bottomcolor = Q_atoi(val);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Con_Printf("%s: bottomcolor unchanged for %s.\n", __FUNCTION__, cl->PlayerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "cl_updaterate");
|
|
||||||
if(val[0] != '\0') {
|
|
||||||
i = Q_atoi(val);
|
|
||||||
if(i < 10) { i = 10; }
|
|
||||||
else if(i > 300) { i = 300; }
|
|
||||||
|
|
||||||
cl->cl_updaterate = 1.0 / i;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "cl_lw");
|
|
||||||
if(val[0] != '\0') {
|
|
||||||
cl->cl_lw = (Q_atoi(val) != 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cl->cl_lw = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "cl_lc");
|
|
||||||
if(val[0] != '\0') {
|
|
||||||
cl->cl_lc = (Q_atoi(val) != 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cl->cl_lc = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = Info_ValueForKey(cl->InfoKeyBuffer, "hltv");
|
|
||||||
if(val[0] != '\0') {
|
|
||||||
cl->padding243C_proxy = (Q_atoi(val) != 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cl->padding243C_proxy = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SV_CheckUpdateRate(&(cl->cl_updaterate));
|
|
||||||
SV_CheckRate(cl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//time based
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_CalcPing
|
|
||||||
// LOCATION: sv_main.c
|
|
||||||
// PATH: A few status functions, called every two seconds.
|
|
||||||
//
|
|
||||||
// Ever wonder why bots have a ping of five? Well read this, and be informed.
|
|
||||||
// Pings are caluclated by averaging out old frames. No real surprises here.
|
|
||||||
*/
|
|
||||||
int SV_CalcPing(client_t *cl) {
|
|
||||||
|
|
||||||
float ping;
|
|
||||||
unsigned int i, count;
|
|
||||||
|
|
||||||
client_frame_t * frame;
|
|
||||||
|
|
||||||
if(cl->padding2438_IsFakeClient) { return(666); } //Bots are soulless headshotting machines
|
|
||||||
|
|
||||||
ping = 0;
|
|
||||||
count = 0;
|
|
||||||
for(i = 0; i < SV_UPDATE_BACKUP; i++) {
|
|
||||||
|
|
||||||
frame = &(cl->padding3480_frames[(cl->netchan1C.incoming_acknowledged - (i + 1)) & SV_UPDATE_MASK]);
|
|
||||||
|
|
||||||
if(frame->ping_time > 0) {
|
|
||||||
ping += frame->ping_time;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count == 0) { return(0); }
|
|
||||||
|
|
||||||
return((ping / count) * 1000);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_ShouldUpdatePing
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_WriteEntitiesToClient
|
|
||||||
//
|
|
||||||
// This calls SV_CalcPing, and returns true if this person needs ping data.
|
|
||||||
*/
|
|
||||||
int SV_ShouldUpdatePing(client_t *client) {
|
|
||||||
|
|
||||||
if(client->padding243C_proxy == 0) {
|
|
||||||
SV_CalcPing(client);
|
|
||||||
return(client->padding2440.buttons & IN_SCORE); //They are viewing the scoreboard. Send them pings.
|
|
||||||
}
|
|
||||||
|
|
||||||
if(global_realtime > client->padding249C_TimeOfNextPingCalc) {
|
|
||||||
|
|
||||||
client->padding249C_TimeOfNextPingCalc += 2;
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_GetNetInfo
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_EmitPings
|
|
||||||
//
|
|
||||||
// This function and its static vars track some of the networking
|
|
||||||
// conditions. I haven't bothered to trace it beyond that, because
|
|
||||||
// this fucntion sucks pretty badly.
|
|
||||||
*/
|
|
||||||
void SV_GetNetInfo(client_t *client, int * arg_4, int * arg_8) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
static int lastping_300[32]; //These static vars will need to be altered to up the max player limit.
|
|
||||||
static int lastloss_301[32];
|
|
||||||
|
|
||||||
i = client - global_svs.clients; //index.
|
|
||||||
if(client->padding249C_TimeOfNextPingCalc < global_realtime) {
|
|
||||||
|
|
||||||
client->padding249C_TimeOfNextPingCalc = global_realtime + 2;
|
|
||||||
lastping_300[i] = SV_CalcPing(client);
|
|
||||||
lastloss_301[i] = client->packet_loss;
|
|
||||||
}
|
|
||||||
|
|
||||||
*arg_4 = lastping_300[i];
|
|
||||||
*arg_8 = lastloss_301[i];
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_CalcClientTime
|
|
||||||
// PATH: SV_ExecuteClientMessage->SV_ComputeLatency
|
|
||||||
//
|
|
||||||
// Another, more critical method of calculating times. This is
|
|
||||||
// directly related to lag compensation, unlike the averaged out ping.
|
|
||||||
*/
|
|
||||||
float SV_CalcClientTime(client_t * cl) {
|
|
||||||
|
|
||||||
int i, temp_sv_unlagsamples, temp_max;
|
|
||||||
|
|
||||||
client_frame_t * var_18_frame_p;
|
|
||||||
int TotalReads = 0;
|
|
||||||
float ReturnVal = 0;
|
|
||||||
|
|
||||||
|
|
||||||
temp_sv_unlagsamples = (int)cvar_sv_unlagsamples.value;
|
|
||||||
if(temp_sv_unlagsamples < 1) { temp_sv_unlagsamples = 1; }
|
|
||||||
else {
|
|
||||||
temp_max = (SV_UPDATE_BACKUP > 16) ? SV_UPDATE_BACKUP : 16; //max()
|
|
||||||
if(temp_sv_unlagsamples > temp_max) { temp_sv_unlagsamples = temp_max; }
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0; i < temp_sv_unlagsamples; i++) {
|
|
||||||
|
|
||||||
var_18_frame_p = &cl->padding3480_frames[(cl->netchan1C.incoming_acknowledged - i) & SV_UPDATE_MASK];
|
|
||||||
if(var_18_frame_p->ping_time > 0) {
|
|
||||||
ReturnVal += var_18_frame_p->ping_time;
|
|
||||||
TotalReads++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(TotalReads == 0) { return(0); }
|
|
||||||
ReturnVal /= TotalReads;
|
|
||||||
|
|
||||||
//There is more to this function in the assembly, but it's crazy code that
|
|
||||||
//doesn't seem to serve any real purpose.
|
|
||||||
|
|
||||||
return(ReturnVal);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_ComputeLatency
|
|
||||||
// PATH: SV_ExecuteClientMessage
|
|
||||||
//
|
|
||||||
// Calls SV_CalcClientTime.
|
|
||||||
*/
|
|
||||||
void SV_ComputeLatency(client_t * cl) {
|
|
||||||
|
|
||||||
cl->ping = SV_CalcClientTime(cl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_UnlagCheckTeleport
|
|
||||||
// PATH: SV_RunCmd->SV_SetupMove
|
|
||||||
//
|
|
||||||
// This 'checks' to see if the entity was teleported over the course of
|
|
||||||
// a frame or so. It's clearly not intended to be perfectly accurate.
|
|
||||||
*/
|
|
||||||
int SV_UnlagCheckTeleport(vec3_t old_pos, vec3_t new_pos) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
for(i = 0; i < 3; i++) {
|
|
||||||
if(fabs(old_pos[i] - new_pos[i]) > 50) { return(1); }
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//thinking
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_PlayerRunPreThink
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_RunCmd
|
|
||||||
//
|
|
||||||
// Calls the mod's prethink function.
|
|
||||||
*/
|
|
||||||
void SV_PlayerRunPreThink(edict_t * ed, float arg_4) {
|
|
||||||
|
|
||||||
gGlobalVariables.time = arg_4;
|
|
||||||
gEntityInterface.pfnPlayerPreThink(ed);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: SV_PlayerRunThink
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: SV_RunCmd
|
|
||||||
//
|
|
||||||
// Might run thinking code if enough time has passed. It seems that
|
|
||||||
// it will also NOT run thinking code if TOO much time has passed.
|
|
||||||
//
|
|
||||||
// Returns 0 if the object removed itself or one otherwise.
|
|
||||||
*/
|
|
||||||
int SV_PlayerRunThink(edict_t * ed, float arg_4, double arg_8) {
|
|
||||||
|
|
||||||
float var_4;
|
|
||||||
|
|
||||||
|
|
||||||
if((ed->v.flags & (FL_KILLME | FL_DORMANT)) == 0) {
|
|
||||||
|
|
||||||
var_4 = ed->v.nextthink;
|
|
||||||
if(var_4 <= 0 || var_4 > arg_4 + arg_8) { return(1); }
|
|
||||||
|
|
||||||
if(var_4 > arg_8) {
|
|
||||||
var_4 = arg_8;
|
|
||||||
}
|
|
||||||
|
|
||||||
ed->v.nextthink = 0;
|
|
||||||
gGlobalVariables.time = var_4;
|
|
||||||
gEntityInterface.pfnThink(ed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if((ed->v.flags & FL_KILLME)) { //Kill them.
|
|
||||||
ED_Free(ed);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(ed->free == 0); //return 1 if it's zero.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//moving
|
|
||||||
|
|
||||||
void SV_SetupMove(client_t * arg_0_client) {
|
|
||||||
|
|
||||||
unsigned int i, j, var_C_entindex;
|
|
||||||
float var_14_finalpush, var_18_lerp_msec, var_1C_ping, temp, var_30;
|
|
||||||
client_frame_t * var_20, * var_24;
|
|
||||||
packet_entities_t * var_2C_packet_ents;
|
|
||||||
entity_state_t * var_34_CurrentEntity, * var_38_FoundEntity;
|
|
||||||
client_t * var_10_client_p;
|
|
||||||
temp_move_t * var_48_trueposition;
|
|
||||||
vec3_t tempvec, tempvec2;
|
|
||||||
|
|
||||||
|
|
||||||
Q_memset(truepositions, 0, sizeof(truepositions));
|
|
||||||
nofind = 1;
|
|
||||||
|
|
||||||
if(gEntityInterface.pfnAllowLagCompensation() == 0 ||
|
|
||||||
(int)cvar_sv_unlag.value == 0 ||
|
|
||||||
arg_0_client->cl_lw == 0 || arg_0_client->cl_lc == 0 ||
|
|
||||||
global_svs.allocated_client_slots <= 1 ||
|
|
||||||
arg_0_client->padding00_used == 0) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nofind = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < global_svs.allocated_client_slots; i++) {
|
|
||||||
|
|
||||||
var_10_client_p = &(global_svs.clients[i]);
|
|
||||||
if(var_10_client_p->padding00_used == 0 || var_10_client_p == arg_0_client) { continue; }
|
|
||||||
|
|
||||||
var_48_trueposition = &(truepositions[i]);
|
|
||||||
|
|
||||||
var_48_trueposition->OldLocation[0] = var_10_client_p->padding4A84->v.origin[0];
|
|
||||||
var_48_trueposition->OldLocation[1] = var_10_client_p->padding4A84->v.origin[1];
|
|
||||||
var_48_trueposition->OldLocation[2] = var_10_client_p->padding4A84->v.origin[2];
|
|
||||||
|
|
||||||
var_48_trueposition->Mins[0] = var_10_client_p->padding4A84->v.absmin[0];
|
|
||||||
var_48_trueposition->Mins[1] = var_10_client_p->padding4A84->v.absmin[1];
|
|
||||||
var_48_trueposition->Mins[2] = var_10_client_p->padding4A84->v.absmin[2];
|
|
||||||
var_48_trueposition->Maxs[0] = var_10_client_p->padding4A84->v.absmax[0];
|
|
||||||
var_48_trueposition->Maxs[1] = var_10_client_p->padding4A84->v.absmax[1];
|
|
||||||
var_48_trueposition->Maxs[2] = var_10_client_p->padding4A84->v.absmax[2];
|
|
||||||
|
|
||||||
var_48_trueposition->IsActive = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(arg_0_client->ping > 1.5) {
|
|
||||||
var_1C_ping = 1.5;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var_1C_ping = arg_0_client->ping;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = cvar_sv_maxunlag.value;
|
|
||||||
if(temp > 0 && var_1C_ping > temp) {
|
|
||||||
var_1C_ping = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_18_lerp_msec = arg_0_client->padding2440.lerp_msec / 1000.0;
|
|
||||||
if(var_18_lerp_msec > .1) {
|
|
||||||
var_18_lerp_msec = .1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var_18_lerp_msec < arg_0_client->cl_updaterate) {
|
|
||||||
var_18_lerp_msec = arg_0_client->cl_updaterate;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_14_finalpush = cvar_sv_unlagpush.value + ((global_realtime - var_1C_ping) - var_18_lerp_msec);
|
|
||||||
|
|
||||||
if(var_14_finalpush > global_realtime) {
|
|
||||||
var_14_finalpush = global_realtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_20 = NULL;
|
|
||||||
for(var_24 = NULL, i = 0; i < (unsigned)SV_UPDATE_BACKUP; i++, var_24 = var_20) {
|
|
||||||
|
|
||||||
var_20 = &(arg_0_client->padding3480_frames[(arg_0_client->netchan1C.outgoing_sequence - 1) & SV_UPDATE_MASK]);
|
|
||||||
var_2C_packet_ents = &(var_20->entities);
|
|
||||||
|
|
||||||
for(j = 0; j < var_2C_packet_ents->max_entities; j++) {
|
|
||||||
|
|
||||||
var_34_CurrentEntity = &(var_2C_packet_ents->entities[j]);
|
|
||||||
if(var_34_CurrentEntity->number <= 0 || (unsigned)var_34_CurrentEntity->number >= global_svs.allocated_client_slots) { continue; }
|
|
||||||
//You know, jge doesn't sound right given how the indexing normally works.
|
|
||||||
|
|
||||||
var_48_trueposition = &(truepositions[var_34_CurrentEntity->number-1]);
|
|
||||||
if(var_48_trueposition->DoNotInterpolate != 0) { continue; }
|
|
||||||
|
|
||||||
if(var_34_CurrentEntity->health <= 0 || (var_34_CurrentEntity->effects & EF_NOINTERP) != 0) {
|
|
||||||
var_48_trueposition->DoNotInterpolate = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var_48_trueposition->FirstIteration == 0) {
|
|
||||||
var_48_trueposition->FirstIteration = 1;
|
|
||||||
}
|
|
||||||
else if(SV_UnlagCheckTeleport(var_34_CurrentEntity->origin, var_48_trueposition->FinalVectors) != 0) {
|
|
||||||
var_48_trueposition->DoNotInterpolate = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var_48_trueposition->FinalVectors[0] = var_34_CurrentEntity->origin[0];
|
|
||||||
var_48_trueposition->FinalVectors[1] = var_34_CurrentEntity->origin[1];
|
|
||||||
var_48_trueposition->FinalVectors[2] = var_34_CurrentEntity->origin[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var_14_finalpush > var_20->sent_time) { break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(i == (unsigned int)SV_UPDATE_BACKUP || var_14_finalpush - var_20->sent_time > 1.0) {
|
|
||||||
|
|
||||||
Q_memset(truepositions, 0, sizeof(truepositions));
|
|
||||||
nofind = 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_2C_packet_ents = &(var_20->entities);
|
|
||||||
if(var_24 == NULL) {
|
|
||||||
|
|
||||||
var_24 = var_20;
|
|
||||||
var_30 = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(var_24->sent_time - var_20->sent_time == 0) {
|
|
||||||
var_30 = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
var_30 = (var_14_finalpush - var_20->sent_time) / (var_24->sent_time - var_20->sent_time);
|
|
||||||
if(var_30 > 1) {
|
|
||||||
var_30 = 1;
|
|
||||||
}
|
|
||||||
else if(var_30 < 0) {
|
|
||||||
var_30 = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(i = 0; i < var_2C_packet_ents->max_entities; i++) {
|
|
||||||
|
|
||||||
var_34_CurrentEntity = &(var_2C_packet_ents->entities[i]);
|
|
||||||
if(var_34_CurrentEntity->number <= 0 || (unsigned)var_34_CurrentEntity->number >= global_svs.allocated_client_slots) { continue; }
|
|
||||||
|
|
||||||
var_C_entindex = var_34_CurrentEntity->number - 1;
|
|
||||||
var_10_client_p = &(global_svs.clients[var_C_entindex]);
|
|
||||||
if(var_10_client_p->padding00_used == 0 || var_10_client_p == arg_0_client) { continue; }
|
|
||||||
|
|
||||||
var_48_trueposition = &(truepositions[var_C_entindex]);
|
|
||||||
if(var_48_trueposition->IsActive == 0 || var_48_trueposition->DoNotInterpolate != 0) { continue; }
|
|
||||||
|
|
||||||
var_38_FoundEntity = SV_FindEntInPack(var_34_CurrentEntity->number, &(var_24->entities));
|
|
||||||
if(var_38_FoundEntity == NULL) {
|
|
||||||
|
|
||||||
tempvec[0] = var_34_CurrentEntity->origin[0];
|
|
||||||
tempvec[1] = var_34_CurrentEntity->origin[1];
|
|
||||||
tempvec[2] = var_34_CurrentEntity->origin[2];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
tempvec2[0] = var_38_FoundEntity->origin[0] - var_34_CurrentEntity->origin[0];
|
|
||||||
tempvec2[1] = var_38_FoundEntity->origin[1] - var_34_CurrentEntity->origin[1];
|
|
||||||
tempvec2[2] = var_38_FoundEntity->origin[2] - var_34_CurrentEntity->origin[2];
|
|
||||||
|
|
||||||
VectorMA(var_34_CurrentEntity->origin, var_30, tempvec2, tempvec);
|
|
||||||
}
|
|
||||||
|
|
||||||
var_48_trueposition->NewLocation[0] = tempvec[0];
|
|
||||||
var_48_trueposition->NewLocation[1] = tempvec[1];
|
|
||||||
var_48_trueposition->NewLocation[2] = tempvec[2];
|
|
||||||
var_48_trueposition->CurrentPosition[0] = tempvec[0];
|
|
||||||
var_48_trueposition->CurrentPosition[1] = tempvec[1];
|
|
||||||
var_48_trueposition->CurrentPosition[2] = tempvec[2];
|
|
||||||
|
|
||||||
if(VectorCompare(tempvec, var_10_client_p->padding4A84->v.origin) == 0) {
|
|
||||||
|
|
||||||
var_10_client_p->padding4A84->v.origin[0] = tempvec[0];
|
|
||||||
var_10_client_p->padding4A84->v.origin[1] = tempvec[1];
|
|
||||||
var_10_client_p->padding4A84->v.origin[2] = tempvec[2];
|
|
||||||
|
|
||||||
SV_LinkEdict(var_10_client_p->padding4A84, 0);
|
|
||||||
var_48_trueposition->IsMoving = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void SV_RestoreMove(client_t * cl) {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
client_t * var_8_client;
|
|
||||||
temp_move_t * var_C_oldevent;
|
|
||||||
|
|
||||||
if(nofind != 0) {
|
|
||||||
nofind = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(gEntityInterface.pfnAllowLagCompensation() == 0 ||
|
|
||||||
global_svs.allocated_client_slots <= 1 ||
|
|
||||||
(int)cvar_sv_unlag.value == 0 ||
|
|
||||||
cl->cl_lw == 0 || cl->cl_lc == 0 ||
|
|
||||||
cl->padding00_used == 0) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0; i < global_svs.allocated_client_slots; i++) {
|
|
||||||
|
|
||||||
var_8_client = &(global_svs.clients[i]);
|
|
||||||
if(var_8_client == cl || var_8_client->padding00_used == 0) { continue; }
|
|
||||||
|
|
||||||
var_C_oldevent = &(truepositions[i]);
|
|
||||||
|
|
||||||
if(VectorCompare(var_C_oldevent->OldLocation, var_C_oldevent->NewLocation) != 0) { continue; } //They didn't actually move.
|
|
||||||
if(var_C_oldevent->IsMoving == 0) { return; }
|
|
||||||
if(var_C_oldevent->IsActive == 0) {
|
|
||||||
|
|
||||||
Con_Printf("%s: Tried to restore an inactive player.\n", __FUNCTION__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(VectorCompare(var_C_oldevent->CurrentPosition, var_8_client->padding4A84->v.origin) != 0) {
|
|
||||||
|
|
||||||
var_8_client->padding4A84->v.origin[0] = var_C_oldevent->OldLocation[0];
|
|
||||||
var_8_client->padding4A84->v.origin[1] = var_C_oldevent->OldLocation[1];
|
|
||||||
var_8_client->padding4A84->v.origin[2] = var_C_oldevent->OldLocation[2];
|
|
||||||
SV_LinkEdict(var_8_client->padding4A84, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//init
|
|
||||||
|
|
||||||
/* DESCRIPTION: SV_User_Init
|
|
||||||
// PATH: SV_Init
|
|
||||||
//
|
|
||||||
// A few local cvars are here.
|
|
||||||
*/
|
|
||||||
void SV_User_Init() {
|
|
||||||
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_maxrate);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_minrate);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_maxupdaterate);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_minupdaterate);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_unlag);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_maxunlag);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_unlagpush);
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_unlagsamples);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/* This is where I'm throwing things related to sv_runcmd(). That function
|
|
||||||
// belongs here too, but is actually in sv_phys
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OSHLDS_SV_USER_HEADER
|
|
||||||
#define OSHLDS_SV_USER_HEADER
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "NET.h"
|
|
||||||
#include "SV_hlds.h"
|
|
||||||
|
|
||||||
|
|
||||||
void SV_GetTrueOrigin(int, vec3_t);
|
|
||||||
void SV_GetTrueMinMax(int, float **, float **);
|
|
||||||
void SV_CopyEdictToPhysent(physent_t *, int, edict_t *);
|
|
||||||
void SetMinMaxSize(edict_t *, const vec3_t, const vec3_t, int);
|
|
||||||
|
|
||||||
void SV_ExtractFromUserinfo(client_t *);
|
|
||||||
|
|
||||||
int SV_CalcPing(client_t *);
|
|
||||||
int SV_ShouldUpdatePing(client_t *);
|
|
||||||
void SV_GetNetInfo(client_t *, int *, int *);
|
|
||||||
void SV_ComputeLatency(client_t *);
|
|
||||||
|
|
||||||
void SV_PlayerRunPreThink(edict_t *, float);
|
|
||||||
int SV_PlayerRunThink(edict_t *, float, double);
|
|
||||||
|
|
||||||
void SV_SetupMove(client_t *);
|
|
||||||
void SV_RestoreMove(client_t *);
|
|
||||||
|
|
||||||
|
|
||||||
void SV_User_Init();
|
|
||||||
|
|
||||||
|
|
||||||
extern unsigned int SV_UPDATE_MASK;
|
|
||||||
extern unsigned int SV_UPDATE_BACKUP;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
#include "Tex.h"
|
|
||||||
#include "com_file.h"
|
|
||||||
#include "FS.hpp"
|
|
||||||
#include "report.h"
|
|
||||||
#include "Q_memdef.h"
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
///global global
|
|
||||||
char texgammatable[0x100];
|
|
||||||
|
|
||||||
|
|
||||||
/*** GLOBALS ***/
|
|
||||||
static int nummiptex;
|
|
||||||
static lumpinfo2_t miptex[MAX_MAP_TEXTURES];
|
|
||||||
static int nTexLumps = 0;
|
|
||||||
static lumpinfo_t *lumpinfo = NULL;
|
|
||||||
static int nTexFiles = 0;
|
|
||||||
static hl_file_t *texfiles[128];
|
|
||||||
|
|
||||||
|
|
||||||
/*** FUNCTIONS ***/
|
|
||||||
|
|
||||||
//This mostly poor code is like a poor man's version of the 'common'
|
|
||||||
//functions. Most of it's simple enough I won't go over it.
|
|
||||||
int lump_sorter(const void *lump1, const void *lump2) {
|
|
||||||
lumpinfo_t *plump1 = (lumpinfo_t *)lump1;
|
|
||||||
lumpinfo_t *plump2 = (lumpinfo_t *)lump2;
|
|
||||||
return Q_strcmp(plump1->name, plump2->name);
|
|
||||||
}
|
|
||||||
void ForwardSlashes(char * string) {
|
|
||||||
|
|
||||||
for(; *string != '\0'; string++) {
|
|
||||||
if(*string == '\\') { *string = '/'; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void SafeRead(hl_file_t *f, void *buffer, int count) {
|
|
||||||
|
|
||||||
if(FS_Read(buffer, count, 1, f) != count) {
|
|
||||||
Sys_Error("%s: File read failure.", __FUNCTION__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void CleanupName(char *in, char *out) { //This seems a pretty useless function...
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0 ; i< 16 ; i++ ) {
|
|
||||||
if(!in[i]) { break; }
|
|
||||||
|
|
||||||
out[i] = toupper(in[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(; i< 16; i++) {
|
|
||||||
out[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int FindMiptex(char *name) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i < nummiptex; i++) {
|
|
||||||
|
|
||||||
if(Q_strcasecmp(name, miptex[i].name) == 0) {
|
|
||||||
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(nummiptex >= MAX_MAP_TEXTURES) {
|
|
||||||
Sys_Error("Exceeded MAX_MAP_TEXTURES");
|
|
||||||
}
|
|
||||||
Q_strncpy(miptex[i].name, name, sizeof(miptex[i].name)-1);
|
|
||||||
miptex[i].name[sizeof(miptex[i].name)-1] = '\0';
|
|
||||||
nummiptex++;
|
|
||||||
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: TEX_InitFromWad
|
|
||||||
// LOCATION: SDK
|
|
||||||
// PATH: Mod_LoadTextures
|
|
||||||
//
|
|
||||||
// I am crap. Rewrite me.
|
|
||||||
*/
|
|
||||||
int TEX_InitFromWad(char *path) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
wadinfo_t wadinfo;
|
|
||||||
char szTmpPath[1024];
|
|
||||||
char szFileBase[1024];
|
|
||||||
char szFileBase2[1028];
|
|
||||||
char *pszWadFile;
|
|
||||||
hl_file_t * texfile;
|
|
||||||
|
|
||||||
Q_strncpy(szTmpPath, path, sizeof(szTmpPath)-1);
|
|
||||||
szTmpPath[sizeof(szTmpPath)-1] = '\0';
|
|
||||||
|
|
||||||
// temporary kludge so we don't have to deal with no occurances of a semicolon
|
|
||||||
// in the path name ..
|
|
||||||
// It's sloppy too.
|
|
||||||
if(Q_strchr(szTmpPath, ';') == NULL) {
|
|
||||||
Q_strcat(szTmpPath, ";");
|
|
||||||
}
|
|
||||||
|
|
||||||
pszWadFile = Q_strtok(szTmpPath, ";"); //strtok is not thread safe, consider rewriting.
|
|
||||||
|
|
||||||
while(pszWadFile != NULL) {
|
|
||||||
|
|
||||||
ForwardSlashes(pszWadFile);
|
|
||||||
COM_FileBase(pszWadFile, szFileBase);
|
|
||||||
strcpy(szFileBase2, szFileBase);
|
|
||||||
COM_DefaultExtension(szFileBase2, ".wad");
|
|
||||||
|
|
||||||
if(Q_strstr(szFileBase, "pldecal") == NULL) {
|
|
||||||
|
|
||||||
//just continue and get the hell out of this sloppy function.
|
|
||||||
pszWadFile = Q_strtok(NULL, ";");
|
|
||||||
}
|
|
||||||
|
|
||||||
texfiles[nTexFiles] = FS_Open(szFileBase2, "rb");
|
|
||||||
|
|
||||||
if(texfiles[nTexFiles] == NULL) {
|
|
||||||
Sys_Error("WARNING: couldn't open %s\n", szFileBase2);
|
|
||||||
}
|
|
||||||
|
|
||||||
nTexFiles++;
|
|
||||||
|
|
||||||
// temp assignment to make things cleaner:
|
|
||||||
texfile = texfiles[nTexFiles-1];
|
|
||||||
Con_Printf("Using WAD File: %s\n", szFileBase2);
|
|
||||||
|
|
||||||
SafeRead(texfile, &wadinfo, sizeof(wadinfo));
|
|
||||||
if(Q_strncmp(wadinfo.identification, "WAD2", 4) != 0 && strncmp(wadinfo.identification, "WAD3", 4) != 0) {
|
|
||||||
|
|
||||||
Sys_Error("TEX_InitFromWad: %s isn't a wadfile", pszWadFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
wadinfo.numlumps = letohost32(wadinfo.numlumps);
|
|
||||||
wadinfo.infotableofs = letohost32(wadinfo.infotableofs);
|
|
||||||
|
|
||||||
FS_Seek(texfile, wadinfo.infotableofs, SEEK_SET);
|
|
||||||
lumpinfo = Q_Realloc(lumpinfo, (nTexLumps + wadinfo.numlumps) * sizeof(lumpinfo_t));
|
|
||||||
|
|
||||||
for(i = 0; i < wadinfo.numlumps; i++) {
|
|
||||||
|
|
||||||
SafeRead(texfile, &lumpinfo[nTexLumps], sizeof(lumpinfo_t) - sizeof(int));
|
|
||||||
CleanupName(lumpinfo[nTexLumps].name, lumpinfo[nTexLumps].name);
|
|
||||||
lumpinfo[nTexLumps].filepos = letohost32(lumpinfo[nTexLumps].filepos);
|
|
||||||
lumpinfo[nTexLumps].disksize = letohost32(lumpinfo[nTexLumps].disksize);
|
|
||||||
lumpinfo[nTexLumps].iTexFile = nTexFiles-1;
|
|
||||||
|
|
||||||
nTexLumps++;
|
|
||||||
}
|
|
||||||
|
|
||||||
pszWadFile = strtok(NULL, ";");
|
|
||||||
}
|
|
||||||
|
|
||||||
qsort((void *)lumpinfo, (size_t)nTexLumps, sizeof(lumpinfo[0]), lump_sorter);
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
void TEX_CleanupWadInfo() {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if(lumpinfo != NULL) {
|
|
||||||
Q_Free(lumpinfo);
|
|
||||||
lumpinfo = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0; i < nTexFiles; i++) {
|
|
||||||
|
|
||||||
FS_Close(texfiles[i]);
|
|
||||||
texfiles[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
nTexLumps = 0;
|
|
||||||
nTexFiles = 0;
|
|
||||||
}
|
|
||||||
int TEX_LoadLump(miptex_t *source, byte *dest) {
|
|
||||||
|
|
||||||
lumpinfo_t key;
|
|
||||||
lumpinfo_t *found;
|
|
||||||
|
|
||||||
CleanupName(source->name, key.name);
|
|
||||||
found = bsearch(&key, (void *)lumpinfo, (size_t)nTexLumps, sizeof(lumpinfo[0]), lump_sorter);
|
|
||||||
|
|
||||||
if(found == NULL) {
|
|
||||||
Con_Printf("%s: Couldn't find texture %s.\n", __FUNCTION__, source->name);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
FS_Seek(texfiles[found->iTexFile], found->filepos, SEEK_SET);
|
|
||||||
SafeRead(texfiles[found->iTexFile], dest, found->disksize); //'dest' will map to a miptex_t structure.
|
|
||||||
return(found->disksize);
|
|
||||||
}
|
|
||||||
void TEX_AddAnimatingTextures() {
|
|
||||||
|
|
||||||
int base;
|
|
||||||
int i, j, k;
|
|
||||||
char name[32];
|
|
||||||
|
|
||||||
base = nummiptex;
|
|
||||||
|
|
||||||
for(i = 0; i < base; i++) {
|
|
||||||
|
|
||||||
if(miptex[i].name[0] != '+' && miptex[i].name[0] != '-') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Q_strncpy(name, miptex[i].name, sizeof(name)-1);
|
|
||||||
name[sizeof(name)-1] = '\0';
|
|
||||||
|
|
||||||
for (j=0 ; j<20 ; j++) {
|
|
||||||
|
|
||||||
if (j < 10) { name[1] = '0'+j; }
|
|
||||||
else { name[1] = 'A'+j-10; } // alternate animation
|
|
||||||
|
|
||||||
// see if this name exists in the wadfile
|
|
||||||
for(k = 0; k < nTexLumps; k++) {
|
|
||||||
if(Q_strcmp(name, lumpinfo[k].name) == 0) {
|
|
||||||
FindMiptex(name); // add to the miptex list
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nummiptex != base) {
|
|
||||||
Con_Printf("%s: added %i additional animating textures.\n", __FUNCTION__, nummiptex - base);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/* Relates to loading TEXTURES. The code in this file is VERY unsafe,
|
|
||||||
// and requires a complete and total overhaul once I know how the damn files
|
|
||||||
// work...
|
|
||||||
*/
|
|
||||||
#ifndef OSHLDS_TEX_HEADER
|
|
||||||
#define OSHLDS_TEX_HEADER
|
|
||||||
|
|
||||||
#include "Mod.h"
|
|
||||||
|
|
||||||
#define MAX_MAP_TEXTURES 0x200
|
|
||||||
|
|
||||||
typedef struct wadinfo_s { //appears to be another way of looking at the dheader_t struct.
|
|
||||||
|
|
||||||
char identification[4]; // should be WAD3
|
|
||||||
int numlumps;
|
|
||||||
int infotableofs;
|
|
||||||
} wadinfo_t;
|
|
||||||
typedef struct lumpinfo_s { //0x24
|
|
||||||
|
|
||||||
int filepos;
|
|
||||||
int disksize;
|
|
||||||
int size; // uncompressed
|
|
||||||
char type;
|
|
||||||
char compression;
|
|
||||||
char pad1, pad2;
|
|
||||||
char name[16]; // must be null terminated
|
|
||||||
|
|
||||||
int iTexFile; // index of the wad this texture is located in
|
|
||||||
|
|
||||||
} lumpinfo_t;
|
|
||||||
typedef struct lumpinfo2_s { //SDK claimed the miptex was a lumpinfo, but the struct is off. 0x40
|
|
||||||
|
|
||||||
char name[32];
|
|
||||||
char padding[32];
|
|
||||||
|
|
||||||
} lumpinfo2_t;
|
|
||||||
|
|
||||||
extern char texgammatable[0x100];
|
|
||||||
|
|
||||||
//functions
|
|
||||||
qboolean TEX_InitFromWad(char *);
|
|
||||||
void TEX_CleanupWadInfo();
|
|
||||||
int TEX_LoadLump(miptex_t *, byte *);
|
|
||||||
void TEX_AddAnimatingTextures();
|
|
||||||
#endif
|
|
||||||
@@ -1,451 +0,0 @@
|
|||||||
#include "VecMath.h"
|
|
||||||
#include "report.h"
|
|
||||||
|
|
||||||
float anglemod(float a) {
|
|
||||||
a = (360.0 / 65536.0) * (((int)(a * (65536.0 / 360.0))) & 0xFFFF);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
HLDS_DLLEXPORT void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) {
|
|
||||||
|
|
||||||
//Since the FPU always casts to doubles, we might as well
|
|
||||||
//keep our temps as doubles.
|
|
||||||
|
|
||||||
double angle; //a temp var
|
|
||||||
double sr, sp, sy, cr, cp, cy;
|
|
||||||
|
|
||||||
angle = angles[1] * (M_PI*2 / 360); //The compiler should convert this to 0.017453292519943295769236907684886
|
|
||||||
sy = sin(angle); //Ugh, a sin in the code... Maybe these days it's a lookup table...
|
|
||||||
cy = cos(angle);
|
|
||||||
angle = angles[0] * (M_PI*2 / 360);
|
|
||||||
sp = sin(angle);
|
|
||||||
cp = cos(angle);
|
|
||||||
angle = angles[2] * (M_PI*2 / 360);
|
|
||||||
sr = sin(angle);
|
|
||||||
cr = cos(angle);
|
|
||||||
|
|
||||||
//I assume all of this is correct, but I admit I only gave it a cursory checking.
|
|
||||||
|
|
||||||
if(forward != NULL) { //I don't think this ever happens...
|
|
||||||
|
|
||||||
forward[0] = cp*cy;
|
|
||||||
forward[1] = cp*sy;
|
|
||||||
forward[2] = -sp;
|
|
||||||
}
|
|
||||||
if(right != NULL) {
|
|
||||||
|
|
||||||
right[0] = (-1*sr*sp*cy+-1*cr*-sy);
|
|
||||||
right[1] = (-1*sr*sp*sy+-1*cr*cy);
|
|
||||||
right[2] = -1*sr*cp;
|
|
||||||
}
|
|
||||||
if(up != NULL) {
|
|
||||||
|
|
||||||
up[0] = (cr*sp*cy+-sr*-sy);
|
|
||||||
up[1] = (cr*sp*sy+-sr*cy);
|
|
||||||
up[2] = cr*cp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void AngleVectorsTranspose(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) {
|
|
||||||
|
|
||||||
double angle;
|
|
||||||
double sr, sp, sy, cr, cp, cy;
|
|
||||||
|
|
||||||
angle = angles[1] * (M_PI*2 / 360);
|
|
||||||
sy = sin(angle);
|
|
||||||
cy = cos(angle);
|
|
||||||
angle = angles[0] * (M_PI*2 / 360);
|
|
||||||
sp = sin(angle);
|
|
||||||
cp = cos(angle);
|
|
||||||
angle = angles[2] * (M_PI*2 / 360);
|
|
||||||
sr = sin(angle);
|
|
||||||
cr = cos(angle);
|
|
||||||
|
|
||||||
if(forward != NULL) {
|
|
||||||
|
|
||||||
forward[0] = cp*cy;
|
|
||||||
forward[1] = (sr*sp*cy+cr*-sy);
|
|
||||||
forward[2] = (cr*sp*cy+-sr*-sy);
|
|
||||||
}
|
|
||||||
if(right != NULL) {
|
|
||||||
|
|
||||||
right[0] = cp*sy;
|
|
||||||
right[1] = (sr*sp*sy+cr*cy);
|
|
||||||
right[2] = (cr*sp*sy+-sr*cy);
|
|
||||||
}
|
|
||||||
if(up != NULL) {
|
|
||||||
|
|
||||||
up[0] = -sp;
|
|
||||||
up[1] = sr*cp;
|
|
||||||
up[2] = cr*cp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void AngleMatrix(const vec3_t angles, vec_t matrix[3][4]) {
|
|
||||||
|
|
||||||
double angle;
|
|
||||||
double sr, sp, sy, cr, cp, cy;
|
|
||||||
|
|
||||||
angle = angles[1] * (M_PI*2 / 360);
|
|
||||||
sy = sin(angle);
|
|
||||||
cy = cos(angle);
|
|
||||||
angle = angles[0] * (M_PI*2 / 360);
|
|
||||||
sp = sin(angle);
|
|
||||||
cp = cos(angle);
|
|
||||||
angle = angles[2] * (M_PI*2 / 360);
|
|
||||||
sr = sin(angle);
|
|
||||||
cr = cos(angle);
|
|
||||||
|
|
||||||
matrix[0][0] = cp*cy;
|
|
||||||
matrix[1][0] = cp*sy;
|
|
||||||
matrix[2][0] = -sp;
|
|
||||||
matrix[0][1] = sr*sp*cy+cr*-sy;
|
|
||||||
matrix[1][1] = sr*sp*sy+cr*cy;
|
|
||||||
matrix[2][1] = sr*cp;
|
|
||||||
matrix[0][2] = (cr*sp*cy+-sr*-sy);
|
|
||||||
matrix[1][2] = (cr*sp*sy+-sr*cy);
|
|
||||||
matrix[2][2] = cr*cp;
|
|
||||||
matrix[0][3] = 0.0;
|
|
||||||
matrix[1][3] = 0.0;
|
|
||||||
matrix[2][3] = 0.0;
|
|
||||||
}
|
|
||||||
void AngleIMatrix(const vec3_t angles, vec_t matrix[3][4]) {
|
|
||||||
|
|
||||||
double angle;
|
|
||||||
double sr, sp, sy, cr, cp, cy;
|
|
||||||
|
|
||||||
angle = angles[1] * (M_PI*2 / 360);
|
|
||||||
sy = sin(angle);
|
|
||||||
cy = cos(angle);
|
|
||||||
angle = angles[0] * (M_PI*2 / 360);
|
|
||||||
sp = sin(angle);
|
|
||||||
cp = cos(angle);
|
|
||||||
angle = angles[2] * (M_PI*2 / 360);
|
|
||||||
sr = sin(angle);
|
|
||||||
cr = cos(angle);
|
|
||||||
|
|
||||||
matrix[0][0] = cp*cy;
|
|
||||||
matrix[0][1] = cp*sy;
|
|
||||||
matrix[0][2] = -sp;
|
|
||||||
matrix[1][0] = sr*sp*cy+cr*-sy;
|
|
||||||
matrix[1][1] = sr*sp*sy+cr*cy;
|
|
||||||
matrix[1][2] = sr*cp;
|
|
||||||
matrix[2][0] = (cr*sp*cy+-sr*-sy);
|
|
||||||
matrix[2][1] = (cr*sp*sy+-sr*cy);
|
|
||||||
matrix[2][2] = cr*cp;
|
|
||||||
matrix[0][3] = 0.0;
|
|
||||||
matrix[1][3] = 0.0;
|
|
||||||
matrix[2][3] = 0.0;
|
|
||||||
}
|
|
||||||
void NormalizeAngles(vec3_t angles) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < 3; i++) {
|
|
||||||
|
|
||||||
if(angles[i] > 180.0) { angles[i] -= 360.0; }
|
|
||||||
else if(angles[i] < -180.0) { angles[i] += 360.0; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double Length(vec3_t v) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
double length;
|
|
||||||
|
|
||||||
length = 0;
|
|
||||||
for(i = 0; i < 3; i++) { length += v[i]*v[i]; }
|
|
||||||
length = sqrt(length);
|
|
||||||
|
|
||||||
return(length);
|
|
||||||
}
|
|
||||||
int VectorCompare(vec3_t v1, vec3_t v2) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i < 3; i++) {
|
|
||||||
// if(fabs(v1[i]-v2[i]) > EQUAL_EPSILON) { return(0); } //This is not how the asm looks...
|
|
||||||
if(v1[i] != v2[i]) { return(0); }
|
|
||||||
}
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VectorMA(vec3_t va, float scale, vec3_t vb, vec3_t vc) {
|
|
||||||
|
|
||||||
vc[0] = va[0] + scale*vb[0];
|
|
||||||
vc[1] = va[1] + scale*vb[1];
|
|
||||||
vc[2] = va[2] + scale*vb[2];
|
|
||||||
}
|
|
||||||
void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross) {
|
|
||||||
|
|
||||||
cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
|
||||||
cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
|
|
||||||
cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
|
|
||||||
}
|
|
||||||
void VectorScale(vec3_t v, vec_t scale, vec3_t out) {
|
|
||||||
|
|
||||||
out[0] = v[0] * scale;
|
|
||||||
out[1] = v[1] * scale;
|
|
||||||
out[2] = v[2] * scale;
|
|
||||||
}
|
|
||||||
vec_t VectorNormalize(vec3_t v) { //Much different in the SDK
|
|
||||||
|
|
||||||
double length, ilength;
|
|
||||||
|
|
||||||
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
|
|
||||||
length = sqrt(length);
|
|
||||||
|
|
||||||
if(length != 0) {
|
|
||||||
|
|
||||||
ilength = 1/length;
|
|
||||||
v[0] *= ilength;
|
|
||||||
v[1] *= ilength;
|
|
||||||
v[2] *= ilength;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VectorInverse(vec3_t v) {
|
|
||||||
|
|
||||||
v[0] = -v[0];
|
|
||||||
v[1] = -v[1];
|
|
||||||
v[2] = -v[2];
|
|
||||||
}
|
|
||||||
void VectorTransform(const vec3_t in1, vec_t in2[3][4], vec3_t out) {
|
|
||||||
|
|
||||||
out[0] = DotProduct(in1, in2[0]) + in2[0][3];
|
|
||||||
out[1] = DotProduct(in1, in2[1]) + in2[1][3];
|
|
||||||
out[2] = DotProduct(in1, in2[2]) + in2[2][3];
|
|
||||||
}
|
|
||||||
//SDK
|
|
||||||
void VectorAngles(const vec3_t forward, vec3_t angles) {
|
|
||||||
|
|
||||||
float tmp, yaw, pitch;
|
|
||||||
|
|
||||||
if(forward[1] == 0 && forward[0] == 0) {
|
|
||||||
|
|
||||||
yaw = 0;
|
|
||||||
if(forward[2] > 0) { pitch = 90; }
|
|
||||||
else { pitch = 270; }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
yaw = (atan2(forward[1], forward[0]) * 180 / M_PI);
|
|
||||||
if(yaw < 0) { yaw += 360; }
|
|
||||||
|
|
||||||
tmp = sqrt(forward[0]*forward[0] + forward[1]*forward[1]);
|
|
||||||
pitch = (atan2(forward[2], tmp) * 180 / M_PI);
|
|
||||||
if(pitch < 0) { pitch += 360; }
|
|
||||||
}
|
|
||||||
angles[0] = pitch;
|
|
||||||
angles[1] = yaw;
|
|
||||||
angles[2] = 0;
|
|
||||||
}
|
|
||||||
void VectorMatrix(vec3_t forward, vec3_t right, vec3_t up) {
|
|
||||||
|
|
||||||
vec3_t tmp;
|
|
||||||
|
|
||||||
if(forward[0] == 0 && forward[1] == 0) {
|
|
||||||
|
|
||||||
right[0] = 1;
|
|
||||||
right[1] = 0;
|
|
||||||
right[2] = 0;
|
|
||||||
up[0] = -forward[2];
|
|
||||||
up[1] = 0;
|
|
||||||
up[2] = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp[0] = 0; tmp[1] = 0; tmp[2] = 1.0;
|
|
||||||
CrossProduct(forward, tmp, right);
|
|
||||||
VectorNormalize(right);
|
|
||||||
CrossProduct(right, forward, up);
|
|
||||||
VectorNormalize(up);
|
|
||||||
}
|
|
||||||
|
|
||||||
//These look to be all inline (or defines) in the SW, but for completeness' sake...
|
|
||||||
vec_t _DotProduct(vec3_t v1, vec3_t v2) {
|
|
||||||
|
|
||||||
return(v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]);
|
|
||||||
}
|
|
||||||
void _VectorSubtract(vec3_t va, vec3_t vb, vec3_t out) {
|
|
||||||
|
|
||||||
out[0] = va[0]-vb[0];
|
|
||||||
out[1] = va[1]-vb[1];
|
|
||||||
out[2] = va[2]-vb[2];
|
|
||||||
}
|
|
||||||
void _VectorAdd(vec3_t va, vec3_t vb, vec3_t out) {
|
|
||||||
|
|
||||||
out[0] = va[0]+vb[0];
|
|
||||||
out[1] = va[1]+vb[1];
|
|
||||||
out[2] = va[2]+vb[2];
|
|
||||||
}
|
|
||||||
void _VectorCopy(vec3_t in, vec3_t out) {
|
|
||||||
out[0] = in[0];
|
|
||||||
out[1] = in[1];
|
|
||||||
out[2] = in[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
//I'm not gonna verify this unless it doesn't work...
|
|
||||||
void R_ConcatRotations(vec_t in1[3][3], vec_t in2[3][3], vec_t out[3][3]) {
|
|
||||||
|
|
||||||
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0];
|
|
||||||
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1];
|
|
||||||
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2];
|
|
||||||
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + in1[1][2] * in2[2][0];
|
|
||||||
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + in1[1][2] * in2[2][1];
|
|
||||||
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + in1[1][2] * in2[2][2];
|
|
||||||
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + in1[2][2] * in2[2][0];
|
|
||||||
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + in1[2][2] * in2[2][1];
|
|
||||||
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2];
|
|
||||||
}
|
|
||||||
void R_ConcatTransforms(vec_t in1[3][4],vec_t in2[3][4], vec_t out[3][4]) {
|
|
||||||
|
|
||||||
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0];
|
|
||||||
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1];
|
|
||||||
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2];
|
|
||||||
out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] + in1[0][2] * in2[2][3] + in1[0][3];
|
|
||||||
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + in1[1][2] * in2[2][0];
|
|
||||||
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + in1[1][2] * in2[2][1];
|
|
||||||
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + in1[1][2] * in2[2][2];
|
|
||||||
out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] + in1[1][2] * in2[2][3] + in1[1][3];
|
|
||||||
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + in1[2][2] * in2[2][0];
|
|
||||||
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + in1[2][2] * in2[2][1];
|
|
||||||
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2];
|
|
||||||
out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + in1[2][2] * in2[2][3] + in1[2][3];
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngleQuaternion(const vec3_t angles, vec4_t quaternion) {
|
|
||||||
|
|
||||||
double angle;
|
|
||||||
double sr, sp, sy, cr, cp, cy;
|
|
||||||
|
|
||||||
angle = angles[2] * 0.5;
|
|
||||||
sy = sin(angle);
|
|
||||||
cy = cos(angle);
|
|
||||||
angle = angles[1] * 0.5;
|
|
||||||
sp = sin(angle);
|
|
||||||
cp = cos(angle);
|
|
||||||
angle = angles[0] * 0.5;
|
|
||||||
sr = sin(angle);
|
|
||||||
cr = cos(angle);
|
|
||||||
|
|
||||||
quaternion[0] = sr*cp*cy-cr*sp*sy; // X
|
|
||||||
quaternion[1] = cr*sp*cy+sr*cp*sy; // Y
|
|
||||||
quaternion[2] = cr*cp*sy-sr*sp*cy; // Z
|
|
||||||
quaternion[3] = cr*cp*cy+sr*sp*sy; // W
|
|
||||||
}
|
|
||||||
//Not the same function. Looks like HL optimizes--probably the same results tho.
|
|
||||||
void QuaternionMatrix(const vec4_t quaternion, vec_t matrix[3][4]) {
|
|
||||||
|
|
||||||
matrix[0][0] = 1.0 - 2.0 * quaternion[1] * quaternion[1] - 2.0 * quaternion[2] * quaternion[2];
|
|
||||||
matrix[1][0] = 2.0 * quaternion[0] * quaternion[1] + 2.0 * quaternion[3] * quaternion[2];
|
|
||||||
matrix[2][0] = 2.0 * quaternion[0] * quaternion[2] - 2.0 * quaternion[3] * quaternion[1];
|
|
||||||
|
|
||||||
matrix[0][1] = 2.0 * quaternion[0] * quaternion[1] - 2.0 * quaternion[3] * quaternion[2];
|
|
||||||
matrix[1][1] = 1.0 - 2.0 * quaternion[0] * quaternion[0] - 2.0 * quaternion[2] * quaternion[2];
|
|
||||||
matrix[2][1] = 2.0 * quaternion[1] * quaternion[2] + 2.0 * quaternion[3] * quaternion[0];
|
|
||||||
|
|
||||||
matrix[0][2] = 2.0 * quaternion[0] * quaternion[2] + 2.0 * quaternion[3] * quaternion[1];
|
|
||||||
matrix[1][2] = 2.0 * quaternion[1] * quaternion[2] - 2.0 * quaternion[3] * quaternion[0];
|
|
||||||
matrix[2][2] = 1.0 - 2.0 * quaternion[0] * quaternion[0] - 2.0 * quaternion[1] * quaternion[1];
|
|
||||||
}
|
|
||||||
//Another function I'm just gonna assume is correct...
|
|
||||||
void QuaternionSlerp(const vec4_t p, vec4_t q, vec_t t, vec4_t qt) {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
double omega, cosom, sinom, sclp, sclq;
|
|
||||||
|
|
||||||
// decide if one of the quaternions is backwards
|
|
||||||
double a = 0;
|
|
||||||
double b = 0;
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
a += (p[i]-q[i])*(p[i]-q[i]);
|
|
||||||
b += (p[i]+q[i])*(p[i]+q[i]);
|
|
||||||
}
|
|
||||||
if (a > b) {
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
q[i] = -q[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cosom = p[0]*q[0] + p[1]*q[1] + p[2]*q[2] + p[3]*q[3];
|
|
||||||
|
|
||||||
if ((1.0 + cosom) > 0.00000001) {
|
|
||||||
if ((1.0 - cosom) > 0.00000001) {
|
|
||||||
omega = acos( cosom );
|
|
||||||
sinom = sin( omega );
|
|
||||||
sclp = sin( (1.0 - t)*omega) / sinom;
|
|
||||||
sclq = sin( t*omega ) / sinom;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sclp = 1.0 - t;
|
|
||||||
sclq = t;
|
|
||||||
}
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
qt[i] = sclp * p[i] + sclq * q[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qt[0] = -p[1];
|
|
||||||
qt[1] = p[0];
|
|
||||||
qt[2] = -p[3];
|
|
||||||
qt[3] = p[2];
|
|
||||||
sclp = sin( (1.0 - t) * 0.5 * M_PI);
|
|
||||||
sclq = sin( t * 0.5 * M_PI);
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
qt[i] = sclp * p[i] + sclq * qt[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p) {
|
|
||||||
|
|
||||||
double dist1, dist2;
|
|
||||||
int sides;
|
|
||||||
|
|
||||||
|
|
||||||
switch (p->signbits) {
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
|
||||||
dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
|
||||||
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
|
||||||
dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
|
||||||
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
|
||||||
dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
|
||||||
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
|
||||||
dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
|
||||||
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Sys_Error("%s: Bad sign bits.", __FUNCTION__);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
sides = 0;
|
|
||||||
if(dist1 >= p->dist) { sides = 1; }
|
|
||||||
if(dist2 < p->dist) { sides |= 2; }
|
|
||||||
|
|
||||||
return(sides);
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/* Straight out of QW and the SDK.
|
|
||||||
// Good thing about math is it's tried and true for several thousand years.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "world.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
|
|
||||||
#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
|
|
||||||
#define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];}
|
|
||||||
#define VectorAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];}
|
|
||||||
#define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];}
|
|
||||||
#define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
|
|
||||||
#define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
|
|
||||||
#define VectorLength(a) Length(a)
|
|
||||||
|
|
||||||
#define EQUAL_EPSILON 0.001 //Note to self--look into this fudge factor.
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265358979323846 //I so want to play with this...
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//For some annoying reason, using 'const' on vec_t arrays makes incompatible pointer errors. Bug in the compiler? Weird thing I missed? It's not really a big deal, just...
|
|
||||||
float anglemod(float a);
|
|
||||||
HLDS_DLLEXPORT void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
|
|
||||||
void AngleVectorsTranspose(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
|
|
||||||
void AngleMatrix(const vec3_t angles, vec_t matrix[3][4]);
|
|
||||||
void AngleIMatrix(const vec3_t angles, vec_t matrix[3][4]);
|
|
||||||
void NormalizeAngles(vec3_t angles);
|
|
||||||
|
|
||||||
double Length(vec3_t v);
|
|
||||||
int VectorCompare(vec3_t v1, vec3_t v2);
|
|
||||||
void VectorMA(vec3_t va, float scale, vec3_t vb, vec3_t vc);
|
|
||||||
void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross);
|
|
||||||
void VectorScale(vec3_t v, vec_t scale, vec3_t out);
|
|
||||||
vec_t VectorNormalize(vec3_t v);
|
|
||||||
void VectorInverse(vec3_t v);
|
|
||||||
void VectorTransform(const vec3_t in1, vec_t in2[3][4], vec3_t out);
|
|
||||||
|
|
||||||
void VectorMatrix(vec3_t forward, vec3_t right, vec3_t up);
|
|
||||||
void VectorAngles(const vec3_t forward, vec3_t angles);
|
|
||||||
|
|
||||||
|
|
||||||
vec_t _DotProduct(vec3_t v1, vec3_t v2);
|
|
||||||
void _VectorSubtract(vec3_t va, vec3_t vb, vec3_t out);
|
|
||||||
void _VectorAdd(vec3_t va, vec3_t vb, vec3_t out);
|
|
||||||
void _VectorCopy(vec3_t in, vec3_t out);
|
|
||||||
|
|
||||||
void R_ConcatRotations(vec_t in1[3][3], vec_t in2[3][3], vec_t out[3][3]);
|
|
||||||
void R_ConcatTransforms(vec_t in1[3][4], vec_t in2[3][4], vec_t out[3][4]);
|
|
||||||
|
|
||||||
void AngleQuaternion(const vec3_t angles, vec4_t quaternion);
|
|
||||||
void QuaternionMatrix(const vec4_t quaternion, vec_t matrix[3][4]);
|
|
||||||
void QuaternionSlerp(const vec4_t p, vec4_t q, vec_t t, vec4_t qt);
|
|
||||||
|
|
||||||
// If you can read this, you're a better man than I.
|
|
||||||
// Orm more patient. I went the easy route and stole from QW.
|
|
||||||
|
|
||||||
int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p);
|
|
||||||
|
|
||||||
#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \
|
|
||||||
(((p)->type < 3)? \
|
|
||||||
( \
|
|
||||||
((p)->dist <= (emins)[(p)->type])? \
|
|
||||||
1 \
|
|
||||||
: \
|
|
||||||
( \
|
|
||||||
((p)->dist >= (emaxs)[(p)->type])?\
|
|
||||||
2 \
|
|
||||||
: \
|
|
||||||
3 \
|
|
||||||
) \
|
|
||||||
) \
|
|
||||||
: \
|
|
||||||
BoxOnPlaneSide( (emins), (emaxs), (p)))
|
|
||||||
@@ -1,780 +0,0 @@
|
|||||||
#include "banlist.h"
|
|
||||||
#include "cmd.h"
|
|
||||||
#include "cvar.h"
|
|
||||||
#include "report.h"
|
|
||||||
#include "Q_memdef.h"
|
|
||||||
#include "FS.hpp"
|
|
||||||
#include "inetaton.h"
|
|
||||||
#include "libcprops-0.1.8/avl.h"
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define SIZEOF_CD_KEY 32
|
|
||||||
|
|
||||||
/*** Structs ***/
|
|
||||||
typedef struct IP_avl_container_s {
|
|
||||||
|
|
||||||
cp_avltree * RootNodeOfTree;
|
|
||||||
struct IP_avl_container_s * PreviousMask;
|
|
||||||
struct IP_avl_container_s * NextMask;
|
|
||||||
|
|
||||||
uint32 subnetmask;
|
|
||||||
} IP_avl_container_t;
|
|
||||||
|
|
||||||
|
|
||||||
/*** Globals ***/
|
|
||||||
static IP_avl_container_t * ip_banlist = NULL;
|
|
||||||
static cp_avltree * cd_banlist = NULL;
|
|
||||||
//static cp_avltree * name_banlist = NULL;
|
|
||||||
|
|
||||||
cvar_t cvar_sv_filterban = { "sv_filterban", "1", 0, 0, 0 };
|
|
||||||
cvar_t cvar_announce_bans = { "announce_bans", "1", FCVAR_PROTECTED , 0, 0 };
|
|
||||||
static cvar_t cvar_cd_key_ban_file = { "cd_key_ban_file", "cdbans.cfg", 0, 0, 0 };
|
|
||||||
static cvar_t cvar_ip_addr_ban_file = { "ip_addr_ban_file", "ipbans.cfg", 0, 0, 0 };
|
|
||||||
static cvar_t cvar_name_ban_file = { "name_ban_file", "namebans.cfg", 0, 0, 0 };
|
|
||||||
|
|
||||||
|
|
||||||
/*** Functions ***/
|
|
||||||
void Banlist_Init() {
|
|
||||||
|
|
||||||
Banlist_ReadBansFromFile();
|
|
||||||
}
|
|
||||||
void Banlist_CvarInit() {
|
|
||||||
|
|
||||||
Cvar_RegisterVariable(&cvar_sv_filterban);
|
|
||||||
Cvar_RegisterVariable(&cvar_cd_key_ban_file);
|
|
||||||
Cvar_RegisterVariable(&cvar_ip_addr_ban_file);
|
|
||||||
Cvar_RegisterVariable(&cvar_name_ban_file);
|
|
||||||
Cvar_RegisterVariable(&cvar_announce_bans);
|
|
||||||
}
|
|
||||||
void Banlist_ClearBans() {
|
|
||||||
|
|
||||||
void ClearCDKeys();
|
|
||||||
void ClearIPv4();
|
|
||||||
}
|
|
||||||
void Banlist_ReadBansFromFile() {
|
|
||||||
|
|
||||||
Banlist_ReadBansFromFile_CD();
|
|
||||||
Banlist_ReadBansFromFile_IPv4();
|
|
||||||
}
|
|
||||||
void Banlist_WriteBansToFile() {
|
|
||||||
|
|
||||||
Banlist_WriteBansToFile_CD();
|
|
||||||
Banlist_WriteBansToFile_IPv4();
|
|
||||||
}
|
|
||||||
void Banlist_Shutdown() {
|
|
||||||
|
|
||||||
Banlist_WriteBansToFile();
|
|
||||||
Banlist_ClearBans();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** CD keys ***/
|
|
||||||
int CompareCDkeys(void * a, void * b) { //wrapper for memcmp, since they won't know the key size.
|
|
||||||
return(Q_memcmp(a, b, SIZEOF_CD_KEY));
|
|
||||||
}
|
|
||||||
void * KeyDup(void * a) { //Similarly, an implementation of strdup that knows the sizes.
|
|
||||||
register void * ret;
|
|
||||||
|
|
||||||
ret = Q_Malloc(SIZEOF_CD_KEY);
|
|
||||||
CHECK_MEMORY_MALLOC(ret);
|
|
||||||
return(Q_memcpy(ret, a, SIZEOF_CD_KEY));
|
|
||||||
}
|
|
||||||
void KeyFree(void * a) { //and again for free, though this time I guess we could've just used free.
|
|
||||||
Q_Free(a);
|
|
||||||
}
|
|
||||||
int CDKeyCallBackFunction(cp_avlnode * node, hl_file_t * fp) {
|
|
||||||
|
|
||||||
// This function has to conform to the callback's requests. We return !0 if
|
|
||||||
// we want to terminate early. Otherwise we write our node to the file.
|
|
||||||
|
|
||||||
//We are traversing the tree. Don't modify it.
|
|
||||||
if((unsigned)time(NULL) > (unsigned int)node->value) { return(0); } //expired
|
|
||||||
if(FS_FPrintf(fp, "%s %010u\n", (char *)node->key, (unsigned int)node->value) == -1) { return(1); }
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: BanCDKey
|
|
||||||
//
|
|
||||||
// The easiest of the bans. CD keys don't have vague comparisons; the size
|
|
||||||
// is constant, and there are no wildcards.
|
|
||||||
//
|
|
||||||
// Returns 0 on success, or nonzero (i) if there was a problem (malloc and so).
|
|
||||||
*/
|
|
||||||
int BanCDKey(char key[32], unsigned int time) {
|
|
||||||
|
|
||||||
//First things first: If this is the first of our banned keys,
|
|
||||||
//allocate a new list.
|
|
||||||
if(cd_banlist == NULL) {
|
|
||||||
cd_banlist = cp_avltree_create_by_option(COLLECTION_MODE_NOSYNC | //WE handle locking.
|
|
||||||
COLLECTION_MODE_COPY | //keys must be copied into memory
|
|
||||||
COLLECTION_MODE_DEEP,
|
|
||||||
(cp_compare_fn)CompareCDkeys,
|
|
||||||
(cp_copy_fn)KeyDup, KeyFree, //We might want to wrap this so we can choke if a memory failure occurs.
|
|
||||||
NULL, NULL);
|
|
||||||
if(cd_banlist == NULL) {
|
|
||||||
Con_Printf("%s: Memory failure allocating new binary tree. Ban not added.\n", __FUNCTION__);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//well, that was fun. Insert it.
|
|
||||||
//This library's pretty nice, if hard to configure for mingw.
|
|
||||||
//I tried writing my own AVL tree. It was very frustrating.
|
|
||||||
if(cp_avltree_insert(cd_banlist, (void *)key, (void *)time) == NULL) {
|
|
||||||
|
|
||||||
//oh oh, memory failure.
|
|
||||||
Con_Printf("%s: Failed to add key. Probably memory, but I'm too lazy to check.\n", __FUNCTION__);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: UnbanCDKey
|
|
||||||
//
|
|
||||||
// Searches for and removes (frees) a CD key that is banned.
|
|
||||||
// Returns 0 on success or nonzero (1) if not found.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int UnbanCDKey(char key[32]) {
|
|
||||||
|
|
||||||
|
|
||||||
if(cd_banlist == NULL) { return(1); }
|
|
||||||
|
|
||||||
if(cp_avltree_delete(cd_banlist, key) == NULL) {
|
|
||||||
|
|
||||||
//This function returns the mapped value, which if you've forgotten,
|
|
||||||
//is actually an int (void *d). Or null if not found. That makes this a
|
|
||||||
//little odd, but legit. We just have to make sure 0 is never a valid
|
|
||||||
//value for ban time, which since that's in 1970, is reasonable.
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cp_avltree_count(cd_banlist) == 0) { //tree is empty
|
|
||||||
cp_avltree_destroy(cd_banlist);
|
|
||||||
cd_banlist = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: IsCDKeyBanned
|
|
||||||
//
|
|
||||||
// Searches the list. Returns 1 if a key should not be allowed, or
|
|
||||||
// 0 if it should be. Ah, but here's the catch: the cvar sv_filterban
|
|
||||||
// reverses the criteria. If sv_filterban is 1, as is default, anybody
|
|
||||||
// on the list is denied access. But if sv_filterban is 0, then this becomes
|
|
||||||
// an allow list, and if you're NOT on the list, you aren't getting in.
|
|
||||||
//
|
|
||||||
*/
|
|
||||||
int IsCDKeyBanned(char key[32]) {
|
|
||||||
|
|
||||||
unsigned int ban_expiration;
|
|
||||||
int RetIfUnlisted;
|
|
||||||
int RetIfListed;
|
|
||||||
|
|
||||||
//This is wholly unnecessary. Helps make this clearer though, instead of rampant nots.
|
|
||||||
if(cvar_sv_filterban.value == 1) { //normal behaviour, list acts as blacklist.
|
|
||||||
RetIfUnlisted = 0;
|
|
||||||
RetIfListed = 1;
|
|
||||||
}
|
|
||||||
else { //inverse behavour, list is now whitelist.
|
|
||||||
RetIfUnlisted = 1;
|
|
||||||
RetIfListed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(cd_banlist == NULL) { return(RetIfUnlisted); }
|
|
||||||
|
|
||||||
ban_expiration = (unsigned int)cp_avltree_get(cd_banlist, key);
|
|
||||||
if(ban_expiration == 0) { //not found
|
|
||||||
return(RetIfUnlisted);
|
|
||||||
}
|
|
||||||
else if(ban_expiration == (unsigned int)-1) { //entry never expires
|
|
||||||
return(RetIfListed);
|
|
||||||
}
|
|
||||||
else if(ban_expiration < (unsigned)time(NULL)) { //Ban is still listed, but has expired.
|
|
||||||
|
|
||||||
cp_avltree_delete(cd_banlist, key);
|
|
||||||
return(RetIfUnlisted);
|
|
||||||
}
|
|
||||||
else { //ban hasn't expired. Destroy them.
|
|
||||||
return(RetIfListed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClearCDKeys() {
|
|
||||||
cp_avltree_destroy(cd_banlist);
|
|
||||||
cd_banlist = NULL;
|
|
||||||
}
|
|
||||||
void Banlist_ReadBansFromFile_CD() {
|
|
||||||
|
|
||||||
//If these ban lists somehow can manage to get too unwieldly, well,
|
|
||||||
//we'll have to read them in parts now won't we...
|
|
||||||
unsigned int i, bantime, curtime;
|
|
||||||
char tempkey[SIZEOF_CD_KEY];
|
|
||||||
char * filep;
|
|
||||||
const char * curfilep;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
filep = COM_LoadFileForMe(cvar_cd_key_ban_file.string, NULL);
|
|
||||||
if(filep == NULL) { return; } //There not being one is normal for some.
|
|
||||||
|
|
||||||
curfilep = filep;
|
|
||||||
i = 0;
|
|
||||||
curtime = time(NULL);
|
|
||||||
while(1) {
|
|
||||||
|
|
||||||
curfilep = COM_Parse(curfilep);
|
|
||||||
if(global_com_token[0] == '\0') { break; }
|
|
||||||
|
|
||||||
//First should be the key.
|
|
||||||
if(strlen(global_com_token) != 32) {
|
|
||||||
|
|
||||||
Con_Printf("%s: Expected CD key, got %s.\n", __FUNCTION__, global_com_token);
|
|
||||||
continue; //continue because it could just be some garbage, and that way we can recover.
|
|
||||||
}
|
|
||||||
|
|
||||||
//We could make sure each char is hex, but why bother? If the admin's
|
|
||||||
//screwing around, that's his problem.
|
|
||||||
Q_memcpy(tempkey, global_com_token, SIZEOF_CD_KEY);
|
|
||||||
|
|
||||||
//Now get the time.
|
|
||||||
curfilep = COM_Parse(curfilep);
|
|
||||||
if(global_com_token[0] == '\0') { break; }
|
|
||||||
|
|
||||||
bantime = Q_atoi(global_com_token);
|
|
||||||
if(bantime < curtime && bantime != (unsigned)-1) { continue; }
|
|
||||||
|
|
||||||
//Add it.
|
|
||||||
BanCDKey(tempkey, bantime);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Con_Printf("Loaded %u CD keys into %s.\n", i, (cvar_sv_filterban.value == 1) ? "blacklist" : "whitelist");
|
|
||||||
COM_FreeFile(filep);
|
|
||||||
}
|
|
||||||
void Banlist_WriteBansToFile_CD() {
|
|
||||||
|
|
||||||
hl_file_t * fp;
|
|
||||||
|
|
||||||
|
|
||||||
if(cd_banlist == NULL || cvar_cd_key_ban_file.string[0] == '\0') { return; }
|
|
||||||
|
|
||||||
fp = FS_Open(cvar_cd_key_ban_file.string, "wb");
|
|
||||||
if(fp == NULL) { //Not easy. A readonly file could do it though.
|
|
||||||
|
|
||||||
Con_Printf("%s: Couldn't open file \"%s\" for writing.\n", __FUNCTION__, cvar_cd_key_ban_file.string);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Okay, open file. We can sprintf strings in bulk, output each line, etc.
|
|
||||||
//Plenty of options, but this usually doesn't happen during resource
|
|
||||||
//intensive times, so it doesn't really matter.
|
|
||||||
|
|
||||||
//This function can traverse the tree in three ways. or each node it calls
|
|
||||||
//the passed function, and gives that function the node and the last arg.
|
|
||||||
cp_avltree_callback(cd_banlist, (cp_callback_fn)CDKeyCallBackFunction, (void *)fp);
|
|
||||||
|
|
||||||
//We're done.
|
|
||||||
FS_Close(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** IPv4 ***/
|
|
||||||
//The callback function only lets us pass one arg. We have two. Let's pass a struct.
|
|
||||||
typedef struct tempstruct_s {
|
|
||||||
|
|
||||||
hl_file_t * fp;
|
|
||||||
char SubnetMaskStr[16];
|
|
||||||
} tempstruct_t;
|
|
||||||
|
|
||||||
int CompareIPv4(uint32 a, uint32 b) { //Oh, the horror.
|
|
||||||
return(a-b);
|
|
||||||
}
|
|
||||||
int IPv4CallBackFunction(cp_avlnode * node, tempstruct_t * args) {
|
|
||||||
|
|
||||||
union ipocts {
|
|
||||||
uint32 asNum;
|
|
||||||
byte asByte[4];
|
|
||||||
} IPv4;
|
|
||||||
|
|
||||||
|
|
||||||
IPv4.asNum = hosttobe32((uint32)node->key); //We need to write this as chars, so we'll have an easier time in big endian.
|
|
||||||
|
|
||||||
//We are traversing the tree. Don't modify it.
|
|
||||||
if((unsigned)time(NULL) > (unsigned int)node->value) { return(0); } //expired
|
|
||||||
if(FS_FPrintf(args->fp, "%u.%u.%u.%u %s %010u\n", IPv4.asByte[0], IPv4.asByte[1], IPv4.asByte[2], IPv4.asByte[3], args->SubnetMaskStr, (unsigned int)node->value) == -1) { return(1); }
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: BanIPv4
|
|
||||||
//
|
|
||||||
// A slightly more complicated set of bans. Different subnet masks (there are
|
|
||||||
// only 33 possible values) have different trees
|
|
||||||
//
|
|
||||||
// Returns 0 on success, or nonzero (i) if there was a problem (malloc and so).
|
|
||||||
*/
|
|
||||||
int __BanIPv4(uint32 IPv4, IP_avl_container_t * tree, unsigned int time) {
|
|
||||||
|
|
||||||
if(cp_avltree_insert(tree->RootNodeOfTree, (void *)(IPv4 & tree->subnetmask), (void *)time) == NULL) {
|
|
||||||
|
|
||||||
//failed for some reason.
|
|
||||||
Con_Printf("%s: Failed to add key. This is most likely a memory error.\n", __FUNCTION__);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
int BanIPv4(uint32 IPv4, uint32 SubnetMask, unsigned int time) {
|
|
||||||
|
|
||||||
IP_avl_container_t * ptr, * new_ptr;
|
|
||||||
|
|
||||||
|
|
||||||
//As a bit of paranoia, check the mask. I need a PARANOIA define...
|
|
||||||
switch(SubnetMask) {
|
|
||||||
|
|
||||||
case 0x00000000:
|
|
||||||
case 0x00000001:
|
|
||||||
case 0x00000003:
|
|
||||||
case 0x00000007:
|
|
||||||
case 0x0000000F:
|
|
||||||
case 0x0000001F:
|
|
||||||
case 0x0000003F:
|
|
||||||
case 0x0000007F:
|
|
||||||
case 0x000000FF:
|
|
||||||
case 0x000001FF:
|
|
||||||
case 0x000003FF:
|
|
||||||
case 0x000007FF:
|
|
||||||
case 0x00000FFF:
|
|
||||||
case 0x00001FFF:
|
|
||||||
case 0x00003FFF:
|
|
||||||
case 0x00007FFF:
|
|
||||||
case 0x0000FFFF:
|
|
||||||
case 0x0001FFFF:
|
|
||||||
case 0x0003FFFF:
|
|
||||||
case 0x0007FFFF:
|
|
||||||
case 0x000FFFFF:
|
|
||||||
case 0x001FFFFF:
|
|
||||||
case 0x003FFFFF:
|
|
||||||
case 0x007FFFFF:
|
|
||||||
case 0x00FFFFFF:
|
|
||||||
case 0x01FFFFFF:
|
|
||||||
case 0x03FFFFFF:
|
|
||||||
case 0x07FFFFFF:
|
|
||||||
case 0x0FFFFFFF:
|
|
||||||
case 0x1FFFFFFF:
|
|
||||||
case 0x3FFFFFFF:
|
|
||||||
case 0x7FFFFFFF:
|
|
||||||
case 0xFFFFFFFF:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Sys_Error("%s: Bad subnet %X.\n", __FUNCTION__, SubnetMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Find the correct container for our subnet mask.
|
|
||||||
for(ptr = ip_banlist; ptr != NULL; ptr = ptr->NextMask) {
|
|
||||||
|
|
||||||
if(ptr->subnetmask == SubnetMask) {
|
|
||||||
return(__BanIPv4(IPv4, ptr, time));
|
|
||||||
}
|
|
||||||
else if(ptr->subnetmask > SubnetMask) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//If we are here, we didn't find it. Malloc a new entry.
|
|
||||||
|
|
||||||
new_ptr = Q_Malloc(sizeof(IP_avl_container_t));
|
|
||||||
if(new_ptr == NULL) {
|
|
||||||
Con_Printf("%s: Memory failure when adding entry.\n", __FUNCTION__);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
new_ptr->RootNodeOfTree = cp_avltree_create((cp_compare_fn)CompareIPv4);
|
|
||||||
if(new_ptr->RootNodeOfTree == NULL) {
|
|
||||||
Con_Printf("%s: Memory failure when adding entry.\n", __FUNCTION__);
|
|
||||||
Q_Free(new_ptr);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
new_ptr->subnetmask = SubnetMask;
|
|
||||||
if(__BanIPv4(IPv4, new_ptr, time) != 0) { //Geez, we failed to allocate the first node.
|
|
||||||
|
|
||||||
cp_avltree_destroy(new_ptr->RootNodeOfTree);
|
|
||||||
Q_Free(new_ptr);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Now to link.
|
|
||||||
if(ip_banlist == NULL) { //If ip_banlist == null, we are the first entry. And the last.
|
|
||||||
|
|
||||||
ip_banlist = new_ptr;
|
|
||||||
ip_banlist->PreviousMask = ip_banlist->NextMask = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(ptr != NULL) { //if ptr != NULL, we know who we need to throw it in front of.
|
|
||||||
|
|
||||||
new_ptr->PreviousMask = ptr->PreviousMask;
|
|
||||||
new_ptr->NextMask = ptr;
|
|
||||||
ptr->PreviousMask = new_ptr;
|
|
||||||
if(new_ptr->PreviousMask != NULL) {
|
|
||||||
new_ptr->PreviousMask->NextMask = new_ptr;
|
|
||||||
}
|
|
||||||
else { //It can only be null if ptr is also ip_banlist
|
|
||||||
ip_banlist = new_ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { //Well shoot, we'll have to loop through to find the last node. Doesn't happen often though, so big deal.
|
|
||||||
|
|
||||||
for(ptr = ip_banlist; ptr->NextMask != NULL; ptr = ptr->NextMask) { }
|
|
||||||
|
|
||||||
ptr->NextMask = new_ptr;
|
|
||||||
new_ptr->PreviousMask = ptr;
|
|
||||||
new_ptr->NextMask = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//And that's everything, I think.
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: UnbanIPv4
|
|
||||||
//
|
|
||||||
// First we find the matching subnet addr.
|
|
||||||
// Then we find the ban.
|
|
||||||
*/
|
|
||||||
int __UnbanIPv4(uint32 IPv4, IP_avl_container_t * tree) {
|
|
||||||
|
|
||||||
if(cp_avltree_delete(tree->RootNodeOfTree, (void *)(IPv4 & tree->subnetmask)) == NULL) {
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
int UnbanIPv4(uint32 IPv4, uint32 SubnetMask) {
|
|
||||||
|
|
||||||
IP_avl_container_t * ptr;
|
|
||||||
|
|
||||||
|
|
||||||
//Paranoia again.
|
|
||||||
switch(SubnetMask) {
|
|
||||||
|
|
||||||
case 0x00000000:
|
|
||||||
case 0x00000001:
|
|
||||||
case 0x00000003:
|
|
||||||
case 0x00000007:
|
|
||||||
case 0x0000000F:
|
|
||||||
case 0x0000001F:
|
|
||||||
case 0x0000003F:
|
|
||||||
case 0x0000007F:
|
|
||||||
case 0x000000FF:
|
|
||||||
case 0x000001FF:
|
|
||||||
case 0x000003FF:
|
|
||||||
case 0x000007FF:
|
|
||||||
case 0x00000FFF:
|
|
||||||
case 0x00001FFF:
|
|
||||||
case 0x00003FFF:
|
|
||||||
case 0x00007FFF:
|
|
||||||
case 0x0000FFFF:
|
|
||||||
case 0x0001FFFF:
|
|
||||||
case 0x0003FFFF:
|
|
||||||
case 0x0007FFFF:
|
|
||||||
case 0x000FFFFF:
|
|
||||||
case 0x001FFFFF:
|
|
||||||
case 0x003FFFFF:
|
|
||||||
case 0x007FFFFF:
|
|
||||||
case 0x00FFFFFF:
|
|
||||||
case 0x01FFFFFF:
|
|
||||||
case 0x03FFFFFF:
|
|
||||||
case 0x07FFFFFF:
|
|
||||||
case 0x0FFFFFFF:
|
|
||||||
case 0x1FFFFFFF:
|
|
||||||
case 0x3FFFFFFF:
|
|
||||||
case 0x7FFFFFFF:
|
|
||||||
case 0xFFFFFFFF:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Sys_Error("%s: Bad subnet %X.\n", __FUNCTION__, SubnetMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Match subnets.
|
|
||||||
for(ptr = ip_banlist; ptr != NULL; ptr = ptr->NextMask) {
|
|
||||||
|
|
||||||
if(ptr->subnetmask == SubnetMask) {
|
|
||||||
if(__UnbanIPv4(IPv4, ptr) != 0) { return(1); } //was not found
|
|
||||||
|
|
||||||
//If we are here, we deleted a node. We now need to see if we must
|
|
||||||
//delete the tree as well.
|
|
||||||
if(cp_avltree_count(ptr->RootNodeOfTree) == 0) { //tree is empty
|
|
||||||
|
|
||||||
//destroy tree
|
|
||||||
cp_avltree_destroy(ptr->RootNodeOfTree);
|
|
||||||
|
|
||||||
//unlink node
|
|
||||||
if(ptr->PreviousMask != NULL) {
|
|
||||||
ptr->PreviousMask = ptr->NextMask;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ip_banlist = ptr->NextMask;
|
|
||||||
}
|
|
||||||
if(ptr->NextMask != NULL) {
|
|
||||||
ptr->NextMask->PreviousMask = ptr->PreviousMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
//destroy node
|
|
||||||
Q_Free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
else if(ptr->subnetmask > SubnetMask) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(1); //Didn't even find the proper container.
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: IsIPv4Banned
|
|
||||||
//
|
|
||||||
// Searches each of the lists. Same return behaviour as CDKeyBanned.
|
|
||||||
*/
|
|
||||||
void * __IsIPv4Banned(uint32 IPv4, IP_avl_container_t * tree) {
|
|
||||||
|
|
||||||
return(cp_avltree_get(tree->RootNodeOfTree, (void *)(IPv4 & tree->subnetmask)));
|
|
||||||
}
|
|
||||||
int IsIPv4Banned(uint32 IPv4) {
|
|
||||||
|
|
||||||
int RetIfUnlisted;
|
|
||||||
int RetIfListed;
|
|
||||||
unsigned int ban_expiration;
|
|
||||||
IP_avl_container_t * ptr, * ptr2;
|
|
||||||
|
|
||||||
|
|
||||||
if(cvar_sv_filterban.value == 1) {
|
|
||||||
RetIfUnlisted = 0;
|
|
||||||
RetIfListed = 1;
|
|
||||||
}
|
|
||||||
else { //inverse behavour, list is now whitelist.
|
|
||||||
RetIfUnlisted = 1;
|
|
||||||
RetIfListed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(ptr = ip_banlist; ptr != NULL; ptr = ptr2) {
|
|
||||||
|
|
||||||
ptr2 = ptr->NextMask;
|
|
||||||
|
|
||||||
|
|
||||||
ban_expiration = (unsigned int)__IsIPv4Banned(IPv4, ptr);
|
|
||||||
if(ban_expiration == 0) { //not found
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if(ban_expiration == (unsigned int)-1) { //entry never expires
|
|
||||||
return(RetIfListed);
|
|
||||||
}
|
|
||||||
else if(ban_expiration < (unsigned)time(NULL)) { //Ban is still listed, but has expired. They could however be explicitly banned by a more precise mask. Regardless, delete old ban.
|
|
||||||
|
|
||||||
__UnbanIPv4(IPv4, ptr);
|
|
||||||
if(cp_avltree_count(ptr->RootNodeOfTree) == 0) { //tree is empty
|
|
||||||
|
|
||||||
cp_avltree_destroy(ptr->RootNodeOfTree);
|
|
||||||
if(ptr->PreviousMask != NULL) {
|
|
||||||
ptr->PreviousMask = ptr->NextMask;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ip_banlist = ptr->NextMask;
|
|
||||||
}
|
|
||||||
if(ptr->NextMask != NULL) {
|
|
||||||
ptr->NextMask->PreviousMask = ptr->PreviousMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_Free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else { //ban hasn't expired. Destroy them.
|
|
||||||
return(RetIfListed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Okay, we got here. No matches then.
|
|
||||||
return(RetIfUnlisted);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: IsSockaddrBanned
|
|
||||||
//
|
|
||||||
// Takes a sockaddr, strips out the sin_addr, and passes it on as an int.
|
|
||||||
// If we update to IPv6 (that'll be tricky in itself), that won't cut it.
|
|
||||||
*/
|
|
||||||
int IsSockaddrBanned(struct sockaddr_in * sender) {
|
|
||||||
|
|
||||||
return(IsIPv4Banned(sender->sin_addr.s_addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ClearIPv4() {
|
|
||||||
|
|
||||||
IP_avl_container_t * ptr, * ptr2;
|
|
||||||
|
|
||||||
for(ptr = ip_banlist; ptr != NULL; ptr = ptr2) {
|
|
||||||
|
|
||||||
ptr2 = ptr->NextMask;
|
|
||||||
cp_avltree_destroy(ptr->RootNodeOfTree);
|
|
||||||
Q_Free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
ip_banlist = NULL;
|
|
||||||
}
|
|
||||||
void Banlist_ReadBansFromFile_IPv4() {
|
|
||||||
|
|
||||||
struct in_addr IPv4, CIDR;
|
|
||||||
unsigned int i, bantime, curtime;
|
|
||||||
char * filep;
|
|
||||||
const char * curfilep;
|
|
||||||
|
|
||||||
|
|
||||||
filep = COM_LoadFileForMe(cvar_ip_addr_ban_file.string, NULL);
|
|
||||||
if(filep == NULL) { return; } //There not being one is normal for some.
|
|
||||||
|
|
||||||
curfilep = filep;
|
|
||||||
i = 0;
|
|
||||||
curtime = time(NULL);
|
|
||||||
while(1) {
|
|
||||||
|
|
||||||
curfilep = COM_Parse(curfilep);
|
|
||||||
if(global_com_token[0] == '\0') { break; }
|
|
||||||
|
|
||||||
//First should be the IP. We can't use inet_addr easily, since -1 is a valid address that we expect to see.
|
|
||||||
if(inet_aton(global_com_token, &IPv4) == 0) {
|
|
||||||
|
|
||||||
Con_Printf("%s: Expected IP address, got %s. Corrupt list?\n", __FUNCTION__, global_com_token);
|
|
||||||
continue; //continue because it could just be some garbage, and we can probably recover.
|
|
||||||
}
|
|
||||||
|
|
||||||
//Now the sub, which'll probably be 255.255.255.255
|
|
||||||
curfilep = COM_Parse(curfilep);
|
|
||||||
if(global_com_token[0] == '\0') { break; }
|
|
||||||
|
|
||||||
if(inet_aton(global_com_token, &CIDR) == 0) {
|
|
||||||
|
|
||||||
Con_Printf("%s: Expected subnet mask, got %s. Corrupt list?\n", __FUNCTION__, global_com_token);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//And finally the time.
|
|
||||||
curfilep = COM_Parse(curfilep);
|
|
||||||
if(global_com_token[0] == '\0') { break; }
|
|
||||||
|
|
||||||
bantime = Q_atoi(global_com_token);
|
|
||||||
if(bantime < curtime && bantime != (unsigned)-1) { continue; }
|
|
||||||
|
|
||||||
//Add it.
|
|
||||||
BanIPv4(ntohl(IPv4.s_addr), ntohl(CIDR.s_addr), bantime);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Con_Printf("Loaded %u IP addresses into %s.\n", i, (cvar_sv_filterban.value == 1) ? "blacklist" : "whitelist");
|
|
||||||
COM_FreeFile(filep);
|
|
||||||
}
|
|
||||||
void Banlist_WriteBansToFile_IPv4() {
|
|
||||||
|
|
||||||
union ipocts {
|
|
||||||
uint32 asNum;
|
|
||||||
byte asByte[4];
|
|
||||||
} sub;
|
|
||||||
IP_avl_container_t * ptr;
|
|
||||||
tempstruct_t args;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(ip_banlist == NULL || cvar_ip_addr_ban_file.string[0] == '\0') { return; }
|
|
||||||
|
|
||||||
args.fp = FS_Open(cvar_ip_addr_ban_file.string, "wb");
|
|
||||||
if(args.fp == NULL) {
|
|
||||||
|
|
||||||
Con_Printf("%s: Couldn't open file \"%s\" for writing.\n", __FUNCTION__, cvar_ip_addr_ban_file.string);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ptr = ip_banlist; ptr != NULL; ptr = ptr->NextMask) {
|
|
||||||
|
|
||||||
//Especially for large bans, it's likely we'll be writing the same
|
|
||||||
//subnet mask tons of times. Save us trouble; cache it.
|
|
||||||
sub.asNum = hosttobe32(ptr->subnetmask);
|
|
||||||
sprintf(args.SubnetMaskStr, "%u.%u.%u.%u", sub.asByte[0], sub.asByte[1], sub.asByte[2], sub.asByte[3]); //can never be larger than 15+1 bytes.
|
|
||||||
|
|
||||||
cp_avltree_callback(ptr->RootNodeOfTree, (cp_callback_fn)IPv4CallBackFunction, (void *)&args);
|
|
||||||
}
|
|
||||||
|
|
||||||
FS_Close(args.fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* DESCRIPTION: ParseBanString
|
|
||||||
//
|
|
||||||
// Parses a string from input into a workable ban.
|
|
||||||
// Returns 0 on success.
|
|
||||||
//
|
|
||||||
// Examples: (input will remove the preceding 'ban')
|
|
||||||
// 4.224.234.200 //bans that address
|
|
||||||
// 3.3.3.3 255.255.255.0 //bans all 3.3.3.x addresses
|
|
||||||
// 3.3.3.0/23 // bans anything on 3.3.[2-3].x I think.
|
|
||||||
*/
|
|
||||||
int ParseBanString(const char *arg, const char ToBanOrNotToBan) {
|
|
||||||
|
|
||||||
char temparray[80];
|
|
||||||
char *ptr = NULL;
|
|
||||||
unsigned int IPaddress;
|
|
||||||
unsigned int CIDR = 0xFFFFFFFF;
|
|
||||||
short int temp;
|
|
||||||
|
|
||||||
strncpy(temparray, arg, 79);
|
|
||||||
|
|
||||||
ptr = strpbrk(temparray, " /"); // Is there a space or a slash afterwards?
|
|
||||||
if(ptr != NULL) { // Yes there is.
|
|
||||||
|
|
||||||
ptr[0] = '\0';
|
|
||||||
do { ptr++; } while(*ptr == ' ' || *ptr == '/');
|
|
||||||
|
|
||||||
temp = atoi(ptr);
|
|
||||||
if(temp < 1 || temp > 32) { //Not CIDR. Don't be fooled by the var names
|
|
||||||
CIDR = inet_addr(ptr);
|
|
||||||
}
|
|
||||||
else { //else it must be that CIDR notation.
|
|
||||||
CIDR = 0;
|
|
||||||
for(IPaddress = 0; IPaddress < 32; IPaddress++) { //Var reuse as a counter.
|
|
||||||
|
|
||||||
if(temp >= 0) {
|
|
||||||
temp--;
|
|
||||||
CIDR++;
|
|
||||||
}
|
|
||||||
CIDR = CIDR<<1;
|
|
||||||
}
|
|
||||||
CIDR = htonl(CIDR);
|
|
||||||
}
|
|
||||||
if (CIDR == INADDR_NONE || CIDR == 0) { //banning everyone sounds a lil extreme
|
|
||||||
return(126);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Now for the actual address.
|
|
||||||
|
|
||||||
IPaddress = inet_addr(temparray);
|
|
||||||
|
|
||||||
if(IPaddress == INADDR_NONE || IPaddress == 0) {
|
|
||||||
// Not an Ip address. That's bad.
|
|
||||||
return(127);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ToBanOrNotToBan) { //Or, did the user type 'un' in front of that 'ban'?
|
|
||||||
return(BanIP(IPaddress, CIDR));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return(UnbanIP(IPaddress, CIDR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
// This class came from the master, though classes were removed.
|
|
||||||
// Bans can be by IP or by CD key. IP bans are checked right after a packet
|
|
||||||
// is received. CD key bans are checked for connect messages, since that's
|
|
||||||
// the only time they are transmitted.
|
|
||||||
*/
|
|
||||||
#ifndef OSHLDS_BANLIST_HEADER
|
|
||||||
#define OSHLDS_BANLIST_HEADER
|
|
||||||
#include "NET.h"
|
|
||||||
|
|
||||||
|
|
||||||
//Todo: use in_addr instead of uint32 everywhere. Just in case.
|
|
||||||
|
|
||||||
void Banlist_Init();
|
|
||||||
void Banlist_CvarInit();
|
|
||||||
void Banlist_ClearBans();
|
|
||||||
void Banlist_ReadBansFromFile();
|
|
||||||
void Banlist_WriteBansToFile();
|
|
||||||
void Banlist_Shutdown();
|
|
||||||
|
|
||||||
|
|
||||||
int IsSockaddrBanned(struct sockaddr_in *);
|
|
||||||
|
|
||||||
int BanIPv4(uint32, uint32, unsigned int); //s_addr may be typecast to int
|
|
||||||
int UnbanIPv4(uint32, uint32);
|
|
||||||
int IsIPv4Banned(uint32);
|
|
||||||
|
|
||||||
//The char arrays are all const, but as they are cast to void *s, it is not reasonable to declare this.
|
|
||||||
int BanCDKey(char key[32], unsigned int time);
|
|
||||||
int UnbanCDKey(char key[32]);
|
|
||||||
int IsCDKeyBanned(char key[32]);
|
|
||||||
|
|
||||||
int BanName(char name[32], unsigned int time);
|
|
||||||
int UnbanName(char name[32]);
|
|
||||||
int IsNameBanned(char name[32]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ClearCDKeys();
|
|
||||||
void Banlist_ReadBansFromFile_CD();
|
|
||||||
void Banlist_WriteBansToFile_CD();
|
|
||||||
|
|
||||||
void ClearIPv4();
|
|
||||||
void Banlist_ReadBansFromFile_IPv4();
|
|
||||||
void Banlist_WriteBansToFile_IPv4();
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,63 +0,0 @@
|
|||||||
#ifndef OSHLDS_CMD_HEADER
|
|
||||||
#define OSHLDS_CMD_HEADER
|
|
||||||
|
|
||||||
#include "endianin.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
|
|
||||||
//defines
|
|
||||||
#define MAX_ALIAS_NAME 32
|
|
||||||
#define MAX_ARGS 80
|
|
||||||
typedef void (*xcommand_t) ();
|
|
||||||
typedef enum {
|
|
||||||
cmd_CLIENT = 0,
|
|
||||||
cmd_SERVER
|
|
||||||
} cmd_source_t;
|
|
||||||
|
|
||||||
//structs
|
|
||||||
typedef struct cmdalias_s {
|
|
||||||
struct cmdalias_s *next;
|
|
||||||
char name[MAX_ALIAS_NAME];
|
|
||||||
char *value;
|
|
||||||
// qbyte execlevel;
|
|
||||||
// qbyte restriction;
|
|
||||||
// int flags;
|
|
||||||
} cmdalias_t;
|
|
||||||
typedef struct cmd_function_s {
|
|
||||||
|
|
||||||
struct cmd_function_s *next;
|
|
||||||
const char *name;
|
|
||||||
xcommand_t function; //That's actually a void pointer to a function
|
|
||||||
|
|
||||||
int restriction; //restriction of admin level; could be zmalloced too...
|
|
||||||
// byte zmalloced;
|
|
||||||
} cmd_function_t;
|
|
||||||
|
|
||||||
|
|
||||||
//globals
|
|
||||||
extern cmd_source_t global_cmd_source;
|
|
||||||
|
|
||||||
|
|
||||||
//functions
|
|
||||||
void Cbuf_Init();
|
|
||||||
void Cbuf_Shutdown();
|
|
||||||
void Cbuf_AddText(const char *text);
|
|
||||||
void Cbuf_InsertText(const char *text);
|
|
||||||
void Cbuf_Execute(void);
|
|
||||||
void Cmd_RemoveGameCmds();
|
|
||||||
void Cmd_Shutdown();
|
|
||||||
|
|
||||||
void Cmd_Init();
|
|
||||||
HLDS_DLLEXPORT void Cmd_AddGameCommand(char *, xcommand_t);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT int Cmd_Argc(void);
|
|
||||||
HLDS_DLLEXPORT const char * Cmd_Argv(int);
|
|
||||||
HLDS_DLLEXPORT const char * Cmd_Args(void);
|
|
||||||
void Cmd_ExecuteString(const char *, int);
|
|
||||||
void Cmd_TokenizeString(const char *);
|
|
||||||
qboolean Cmd_Exists(const char *);
|
|
||||||
void Cmd_AddCommand(const char *, xcommand_t);
|
|
||||||
void Cmd_ForwardToServer();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,534 +0,0 @@
|
|||||||
#include <limits.h>
|
|
||||||
#if(defined(_MSC_VER) || defined(__BORLANDC__)) //Might as well be if WINDOWS but not MINGW
|
|
||||||
#include <windows.h> //for max_path
|
|
||||||
#ifndef PATH_MAX
|
|
||||||
#define PATH_MAX MAX_PATH
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include "com_file.h"
|
|
||||||
#include "report.h"
|
|
||||||
#include "Q_memdef.h"
|
|
||||||
|
|
||||||
/*** GLOBALS ***/
|
|
||||||
//used for types 3 and 4
|
|
||||||
static cache_user_t *loadcache; //3
|
|
||||||
static byte *loadbuf; //4
|
|
||||||
static int loadsize; //4
|
|
||||||
|
|
||||||
|
|
||||||
/*** FUNCTIONS ***/
|
|
||||||
//COM_LoadFileLimit is unknown and uncalled it seems
|
|
||||||
//COM_AddAppDirectory messes with the FS, but is uncalled in the DS
|
|
||||||
//COM_CopyFile doesn't do what you'd think and isn't called
|
|
||||||
//COM_ExpandFilename unused
|
|
||||||
//COM_(extended)ExplainDisconnection unused
|
|
||||||
//COM_SetupDirectories is omitted.
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_FileBase
|
|
||||||
// LOCATION: common.c
|
|
||||||
// PATH: lots
|
|
||||||
//
|
|
||||||
// Gets a file name sans dots and other nonsense
|
|
||||||
// Looks weird, but I trust the QW source is good.
|
|
||||||
*/
|
|
||||||
void COM_FileBase(char *in, char *out) {
|
|
||||||
|
|
||||||
char *s, *s2;
|
|
||||||
int length;
|
|
||||||
|
|
||||||
s = in + strlen(in) - 1;
|
|
||||||
|
|
||||||
while (s != in && *s != '.') { s--; }
|
|
||||||
|
|
||||||
for (s2 = s ; *s2 && *s2 != '/' ; s2--) { }
|
|
||||||
|
|
||||||
if (in > s2) {
|
|
||||||
s2 = in;
|
|
||||||
}
|
|
||||||
|
|
||||||
length = s - s2;
|
|
||||||
if (length < 2) {
|
|
||||||
Q_strncpy(out,"?model?", strlen(in));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Q_memcpy(out, s2, length);
|
|
||||||
out[length] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void COM_FileBaseMaxlen(char *in, char *out, int outlen) {
|
|
||||||
|
|
||||||
//This addon shouldn't be necessary since we're at most copying an
|
|
||||||
//idetically sized string into out.
|
|
||||||
|
|
||||||
char *s, *s2;
|
|
||||||
|
|
||||||
s = in + strlen(in) - 1;
|
|
||||||
|
|
||||||
while (s != in && *s != '.') { s--; }
|
|
||||||
|
|
||||||
for (s2 = s ; *s2 && *s2 != '/' ; s2--) { }
|
|
||||||
|
|
||||||
if (in > s2) {
|
|
||||||
s2 = in;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s-s2 < 2) {
|
|
||||||
Q_strncpy (out,"?model?", outlen-1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
s--;
|
|
||||||
outlen--;
|
|
||||||
if (outlen > s-s2)
|
|
||||||
outlen = s-s2;
|
|
||||||
Q_strncpy (out,s2+1, outlen);
|
|
||||||
out[outlen] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_GetGameDir
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: Nowhere. They just use the global.
|
|
||||||
//
|
|
||||||
// Copies com_gamedir into out. The FS needs to handle this though...
|
|
||||||
// Returns strlen(out).
|
|
||||||
*/
|
|
||||||
int COM_GetGameDirSize(char *out, int outlen) {
|
|
||||||
|
|
||||||
return(FS_GetGameDir(out, outlen));
|
|
||||||
}
|
|
||||||
HLDS_DLLEXPORT int COM_GetGameDir(char *out) {
|
|
||||||
|
|
||||||
return(COM_GetGameDirSize(out, PATH_MAX));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_FixSlashes
|
|
||||||
// LOCATION: slash conversion isn't that uncommon
|
|
||||||
// PATH: oo
|
|
||||||
//
|
|
||||||
// '\' becomes '/'. In time (with the Boost filesystem taking care of this
|
|
||||||
// transparently for more than just slashes), I'd like to phase it out.
|
|
||||||
*/
|
|
||||||
int COM_FixSlashes(char * str) {
|
|
||||||
|
|
||||||
char *temp;
|
|
||||||
temp = strchr(str,'\\');
|
|
||||||
|
|
||||||
if(temp == NULL) { return(0); }
|
|
||||||
|
|
||||||
do {
|
|
||||||
*temp = '/';
|
|
||||||
temp++;
|
|
||||||
temp = strchr(temp, '\\');
|
|
||||||
} while(temp != NULL);
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
int COM_FixSlashesWithMem(char * str, unsigned int size) {
|
|
||||||
|
|
||||||
char *temp;
|
|
||||||
int cursize;
|
|
||||||
temp = (char *)memchr((void *)str,'\\', size);
|
|
||||||
|
|
||||||
if(temp == NULL) { return(0); }
|
|
||||||
|
|
||||||
do {
|
|
||||||
*temp = '/';
|
|
||||||
temp++;
|
|
||||||
cursize = size - (temp - str);
|
|
||||||
temp = (char *)memchr((void *)temp, '\\', cursize);
|
|
||||||
} while(temp != NULL);
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_FileExtension
|
|
||||||
// LOCATION: common.c
|
|
||||||
// PATH: Cmd_Exec_f->FileExtension (rather unnecessary)
|
|
||||||
//
|
|
||||||
// Copy/pasted from the QW code. This returns the extension of a file in
|
|
||||||
// a static char array. I don't like static arrays. They can cause threading
|
|
||||||
// issues, so--knowing full well that extensions are usually no more than three
|
|
||||||
// characters, and also knowing that it's only called in one function and
|
|
||||||
// doesn't appear to have an SDK hook--I made a second one.
|
|
||||||
*/
|
|
||||||
char *COM_FileExtension(char *in) {
|
|
||||||
|
|
||||||
static char exten[8];
|
|
||||||
char * dot;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
dot = strrchr(in, '.');
|
|
||||||
if(dot == NULL) { return(""); }
|
|
||||||
|
|
||||||
dot++;
|
|
||||||
|
|
||||||
for(i = 0; (i < 7) && (*dot != '\0'); i++) { exten[i] = dot[i]; }
|
|
||||||
|
|
||||||
exten[i] = '\0';
|
|
||||||
return(exten);
|
|
||||||
}
|
|
||||||
void COM_FileExtensionThreadSafe(const char *in, char *exten, unsigned int SizeofExten) {
|
|
||||||
|
|
||||||
char * dot;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
dot = strrchr(in, '.');
|
|
||||||
if(dot == NULL) { *exten = '\0'; return; }
|
|
||||||
|
|
||||||
dot++;
|
|
||||||
SizeofExten--; //Otherwise we get an off by one. Passing a SizeOfExten of 0 is an error.
|
|
||||||
|
|
||||||
for(i = 0; (i < SizeofExten) && (*dot != '\0'); i++) { exten[i] = dot[i]; }
|
|
||||||
|
|
||||||
exten[i] = '\0';
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: COM_DefaultExtension
|
|
||||||
// LOCATION: common.c
|
|
||||||
// PATH: too much
|
|
||||||
//
|
|
||||||
// This takes a filename and an extension as an argument and checks to see if
|
|
||||||
// the passed filename has an extension. If not it cats on the default one
|
|
||||||
// (arg4). There's no bounds checking in the binary; this is probably unsafe.
|
|
||||||
*/
|
|
||||||
void COM_DefaultExtension(char *path, char *extension) {
|
|
||||||
|
|
||||||
char *src;
|
|
||||||
src = path + strlen(path) - 1;
|
|
||||||
|
|
||||||
while (*src != '/' && src != path) {
|
|
||||||
if (*src == '.') { return; }
|
|
||||||
src--;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_strcat(path, extension); //Danger!
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_SkipPath
|
|
||||||
// LOCATION: common.c
|
|
||||||
// PATH: UPDATE_GetFile (most functions do it locally)
|
|
||||||
//
|
|
||||||
// looks for a slash and then returns a pointer to it. It's strrchr
|
|
||||||
// written all over again but less efficiently.
|
|
||||||
*/
|
|
||||||
char *COM_SkipPath (char *pathname) {
|
|
||||||
|
|
||||||
char * chr;
|
|
||||||
chr = strrchr(pathname, '/');
|
|
||||||
if(chr == NULL) { chr = pathname; }
|
|
||||||
return(chr);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: COM_StripExtension
|
|
||||||
// LOCATION: common.c
|
|
||||||
// PATH: HPAK stuff
|
|
||||||
//
|
|
||||||
// Replaces the last dot with a null and copies it into the buffer. Apparently
|
|
||||||
// "out" and "in" can be the same buffer.
|
|
||||||
*/
|
|
||||||
void COM_StripExtension(char *in, char *out) {
|
|
||||||
|
|
||||||
char *s;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if(out == in) {
|
|
||||||
|
|
||||||
s = strrchr(in, '.');
|
|
||||||
if(s != NULL) { *s = '\0'; }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
s = strrchr(in, '.');
|
|
||||||
i = s - in;
|
|
||||||
Q_memcpy(out, in, i);
|
|
||||||
out[i] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: COM_StripTrailingSlash
|
|
||||||
// LOCATION:
|
|
||||||
// PATH: exec buffer
|
|
||||||
//
|
|
||||||
// This one seems pretty self-explanatory, though it ought to be phased out.
|
|
||||||
*/
|
|
||||||
void COM_StripTrailingSlash(char *pathname) {
|
|
||||||
|
|
||||||
int i = strlen(pathname);
|
|
||||||
if(pathname[i-1] == '/') {
|
|
||||||
pathname[i-1] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_ListMaps
|
|
||||||
// LOCATION: As other names I think. Too messy to bother though.
|
|
||||||
// PATH: console command 'maps'
|
|
||||||
//
|
|
||||||
// Prints out map names. I don't know if the string has the /maps appended
|
|
||||||
// to it or not yet; we'll work that out later, as well as extensions, gamedir,
|
|
||||||
// etc.
|
|
||||||
*/
|
|
||||||
int COM_ListMaps(const char * wildcards) {
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
const char * filename;
|
|
||||||
|
|
||||||
Con_Printf("COM_ListMaps \"%s\":\n", wildcards);
|
|
||||||
|
|
||||||
filename = Sys_FindFirst(wildcards, NULL);
|
|
||||||
while(filename != NULL) {
|
|
||||||
i++;
|
|
||||||
Con_Printf(" %s\n", filename);
|
|
||||||
filename = Sys_FindNext(NULL);
|
|
||||||
}
|
|
||||||
Sys_FindClose();
|
|
||||||
|
|
||||||
Con_Printf("%u matches found.\n", wildcards);
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_LoadFile
|
|
||||||
// LOCATION: SDK
|
|
||||||
// PATH: Theoretically anywhere, since it's in the SDK.
|
|
||||||
//
|
|
||||||
// The args are known, the function cannot be altered.
|
|
||||||
// LoadFileForMe is a wrapper for COM_LoadFile, which is ALSO
|
|
||||||
// in the SDK.
|
|
||||||
//
|
|
||||||
// pLength can be null, for some reason (backwards compat?).
|
|
||||||
// What 'usehunk' does is tell the function HOW to load the file;
|
|
||||||
// I think the functions below better illustrate the types.
|
|
||||||
*/
|
|
||||||
HLDS_DLLEXPORT byte * COM_LoadFile(const char *path, int usehunk, int *pLength) {
|
|
||||||
|
|
||||||
//pLength is a variable passed by reference we are suppossed to put
|
|
||||||
//the size of our loaded file in. It is optional though.
|
|
||||||
|
|
||||||
hl_file_t *file;
|
|
||||||
|
|
||||||
byte *FileData = NULL; //what we end up returning
|
|
||||||
const char *FileName;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
file = FS_Open(path, "rb");
|
|
||||||
|
|
||||||
if(file == NULL) {
|
|
||||||
//No file. How sad.
|
|
||||||
if(pLength != NULL) {
|
|
||||||
*pLength = 0;
|
|
||||||
}
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
len = FS_Size(file);
|
|
||||||
|
|
||||||
switch(usehunk) {
|
|
||||||
case 0:
|
|
||||||
//0 must be small text files, but I'm not sure it's used
|
|
||||||
FileData = (byte *)Z_Malloc(len+1);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
//1 must be regular hunk
|
|
||||||
FileName = strrchr(path, '/');
|
|
||||||
|
|
||||||
if(FileName == NULL) { FileName = path; }
|
|
||||||
else { FileName++; } //worst case oddities, an empty string, shouldn't hurt.
|
|
||||||
|
|
||||||
FileData = (byte *)Hunk_AllocName(len+1, FileName);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
//2 must be temporary file allocation
|
|
||||||
FileData = (byte *)Hunk_TempAlloc(len+1);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
//3 must be caching. I still don't quite understand how that works.
|
|
||||||
FileName = strrchr(path, '/');
|
|
||||||
|
|
||||||
if(FileName == NULL) { FileName = path; }
|
|
||||||
else { FileName++; }
|
|
||||||
|
|
||||||
FileData = (byte *)Cache_Alloc(loadcache, len+1, FileName); //loadcache = global
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
//Similar to case 2. Temp allocation, or allocation to a temporary file pointer.
|
|
||||||
if (len+1 > loadsize) { FileData = (byte *)Hunk_TempAlloc(len+1); }
|
|
||||||
else { FileData = loadbuf; }
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
//And 5 is mallocing the memory. But how is it freed?
|
|
||||||
FileData = (byte *)Q_Malloc(len+1); //Freeing relies on the user.
|
|
||||||
CHECK_MEMORY_MALLOC(FileData);
|
|
||||||
|
|
||||||
//printf("%s: Allocating file %s (%u)\n", __FUNCTION__, path, len+1);
|
|
||||||
|
|
||||||
break;
|
|
||||||
//tempallocmore--case 6--doesn't exist in HL
|
|
||||||
default:
|
|
||||||
Sys_Error ("COM_LoadFile: \"usehunk\" is suppossed to be between 0 and 5. Fix it, modder.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FileData == NULL) {
|
|
||||||
Sys_Error("COM_LoadFile: Couldn't load \"%s\" for some memory related reason.\n", path);
|
|
||||||
FS_Close(file); //since sys_error kills us, why close?
|
|
||||||
}
|
|
||||||
|
|
||||||
//whoawhoawhoa, tacking on a null? I spy a pretty nasty off by one error...
|
|
||||||
//And now len has been +1'd, fixing it.
|
|
||||||
|
|
||||||
FS_Read(FileData, len, 1, file);
|
|
||||||
FileData[len] = '\0';
|
|
||||||
|
|
||||||
FS_Close(file);
|
|
||||||
|
|
||||||
if(pLength != NULL) { *pLength = len; }
|
|
||||||
|
|
||||||
return(FileData);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte *COM_LoadHunkFile(const char *path) { //1
|
|
||||||
return(COM_LoadFile(path, 1, NULL));
|
|
||||||
}
|
|
||||||
byte *COM_LoadTempFile(const char *path, int *pLength) { //2
|
|
||||||
return(COM_LoadFile(path, 2, pLength));
|
|
||||||
}
|
|
||||||
HLDS_DLLEXPORT void COM_LoadCacheFile(const char *path, cache_user_t *cu) { //3
|
|
||||||
|
|
||||||
loadcache = cu;
|
|
||||||
COM_LoadFile(path, 3, NULL);
|
|
||||||
}
|
|
||||||
byte *COM_LoadStackFile(const char *path, void *buffer, int bufsize) { //4
|
|
||||||
|
|
||||||
//This appears to load a file into the passed void * buffer. If that buffer
|
|
||||||
//is too small, temp allocation is done instead. Never called in i386 as
|
|
||||||
//far as I can see. Almost line for line what's in QW.
|
|
||||||
byte *buf;
|
|
||||||
|
|
||||||
loadbuf = (byte *)buffer;
|
|
||||||
loadsize = bufsize;
|
|
||||||
buf = COM_LoadFile(path, 4, NULL);
|
|
||||||
|
|
||||||
return(buf);
|
|
||||||
}
|
|
||||||
HLDS_DLLEXPORT byte * COM_LoadFileForMe(const char *filename, int *pLength) { //5
|
|
||||||
return(COM_LoadFile(filename, 5, pLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wrapper for free. Altering would be a bad idea--it's assumed by us and mods.
|
|
||||||
HLDS_DLLEXPORT void COM_FreeFile(byte *buffer) {
|
|
||||||
Q_Free(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_FileSize
|
|
||||||
// LOCATION: who cares
|
|
||||||
// PATH: here and there
|
|
||||||
//
|
|
||||||
// Gets a file's size. Hey! There's an FS function that does that.
|
|
||||||
*/
|
|
||||||
HLDS_DLLEXPORT int COM_FileSize(char *filename) {
|
|
||||||
|
|
||||||
return(FS_FileSize(filename));
|
|
||||||
}
|
|
||||||
HLDS_DLLEXPORT int COM_CompareFileTime(char *filename1, char *filename2, int *iCompare) {
|
|
||||||
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
i = FS_GetFileTime(filename1);
|
|
||||||
j = FS_GetFileTime(filename2);
|
|
||||||
if(i == 0 || j == 0) {
|
|
||||||
*iCompare = 0;
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i < j) {
|
|
||||||
*iCompare = -1;
|
|
||||||
}
|
|
||||||
else if(i > j) {
|
|
||||||
*iCompare = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*iCompare = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_CreatePath
|
|
||||||
// LOCATION: same as above
|
|
||||||
// PATH: opening, saves, writing, extracting, etc
|
|
||||||
//
|
|
||||||
// Remember the FS function that makes directories? The one that automatically
|
|
||||||
// splits up multiple paths and whatnot? Normally this one looks for the
|
|
||||||
// slashes and calls 'makedir' accordingly, but now all that is needed--thanks
|
|
||||||
// my brilliant planning ahead--is to call it once.
|
|
||||||
*/
|
|
||||||
void COM_CreatePath(char * path) {
|
|
||||||
|
|
||||||
//Actually, minor concern--did I remember to NOT create the file name itself?
|
|
||||||
//Or does boost take care of that? Well, it'll be obvious one way or the
|
|
||||||
//other.
|
|
||||||
FS_CreateDirHierarchy(path, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESCRIPTION: COM_CopyFileChunk
|
|
||||||
// LOCATION: Doesn't appear here, but isn't hard to implement
|
|
||||||
// PATH: Some HPAK add/remove functions
|
|
||||||
//
|
|
||||||
// Two files. It's like strcpy except for some reason we're given the
|
|
||||||
// size. I guess that means don't zero out any pointers. Since there's no
|
|
||||||
// return value and the FS catches exceptions, checking for errors doesn't
|
|
||||||
// seem worthwhile.
|
|
||||||
*/
|
|
||||||
void COM_CopyFileChunk(hl_file_t * file1, hl_file_t * file2, int size) {
|
|
||||||
|
|
||||||
char buffer[1024];
|
|
||||||
|
|
||||||
while(size > 1024) {
|
|
||||||
|
|
||||||
FS_Read(buffer, 1, 1024, file2);
|
|
||||||
FS_Write(buffer, 1, 1024, file1);
|
|
||||||
size -= 1024;
|
|
||||||
}
|
|
||||||
//little bit to go
|
|
||||||
|
|
||||||
FS_Read(buffer, 1, size, file2);
|
|
||||||
FS_Write(buffer, 1, size, file1);
|
|
||||||
|
|
||||||
FS_Flush(file2);
|
|
||||||
FS_Flush(file1);
|
|
||||||
}
|
|
||||||
/* DESCRIPTION: COM_WriteFile
|
|
||||||
// LOCATION: NOT the info_write thing that's in common.c
|
|
||||||
// PATH:
|
|
||||||
//
|
|
||||||
// We make a file and write to it. The target is the game directory.
|
|
||||||
// Until I rework the various systems and better know how HL should
|
|
||||||
// signify which dir to write to, we use this cheap trick:
|
|
||||||
// The first dir on the list should be the game dir (unless another was aded).
|
|
||||||
// So just open the file regularly and it'll be in the right place.
|
|
||||||
*/
|
|
||||||
void COM_WriteFile(char *filename, void *filedata, int length) {
|
|
||||||
|
|
||||||
hl_file_t *fp;
|
|
||||||
char * c;
|
|
||||||
c = strrchr(filename, '/');
|
|
||||||
|
|
||||||
if(c != NULL) {
|
|
||||||
|
|
||||||
*c = '\0';
|
|
||||||
FS_CreateDirHierarchy(filename, NULL);
|
|
||||||
*c = '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
fp = FS_Open(filename, "wb");
|
|
||||||
if (!fp) {
|
|
||||||
Sys_Warning("COM_WriteFile: Couldn't open some file %s.\n", filename);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(FS_Write(filedata, 1, length, fp) != length) {
|
|
||||||
Sys_Warning("COM_WriteFile: Didn't manage to write all of file %s.\n", filename);
|
|
||||||
}
|
|
||||||
FS_Close(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/* This file moves a few functions that deal with opening files to their
|
|
||||||
// own little section.
|
|
||||||
*/
|
|
||||||
#ifndef OSHLDS_COMMON_FILE_HEADER
|
|
||||||
#define OSHLDS_COMMON_FILE_HEADER
|
|
||||||
|
|
||||||
#include "HUNK.h"
|
|
||||||
#include "ModCalls.h"
|
|
||||||
#include "FS.hpp"
|
|
||||||
|
|
||||||
void COM_FileBase(char *, char *);
|
|
||||||
void COM_FileBaseMaxlen(char *, char *, int);
|
|
||||||
HLDS_DLLEXPORT int COM_GetGameDir(char *);
|
|
||||||
int COM_GetGameDirSize(char *, int);
|
|
||||||
int COM_FixSlashes(char *);
|
|
||||||
|
|
||||||
char *COM_FileExtension(char *);
|
|
||||||
void COM_FileExtensionThreadSafe(const char *, char *, unsigned int);
|
|
||||||
void COM_DefaultExtension(char *, char *);
|
|
||||||
void COM_StripExtension(char *, char *);
|
|
||||||
|
|
||||||
int COM_ListMaps(const char *);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT byte * COM_LoadFile(const char *, int, int *);
|
|
||||||
byte * COM_LoadHunkFile(const char *);
|
|
||||||
byte * COM_LoadTempFile(const char *, int *);
|
|
||||||
HLDS_DLLEXPORT void COM_LoadCacheFile(const char *, cache_user_t *);
|
|
||||||
byte * COM_LoadStackFile(const char *, void *, int);
|
|
||||||
HLDS_DLLEXPORT byte * COM_LoadFileForMe(const char *, int *);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT void COM_FreeFile(byte *);
|
|
||||||
|
|
||||||
HLDS_DLLEXPORT int COM_FileSize(char *);
|
|
||||||
HLDS_DLLEXPORT int COM_CompareFileTime(char *, char *, int *);
|
|
||||||
|
|
||||||
void COM_CreatePath(char *);
|
|
||||||
void COM_CopyFileChunk(hl_file_t *, hl_file_t *, int);
|
|
||||||
void COM_WriteFile(char *, void *, int);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loaded 100 of 3745 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user