aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/server/SV_SEND.java
diff options
context:
space:
mode:
authorRene Stoeckel <[email protected]>2004-09-22 19:22:16 +0000
committerRene Stoeckel <[email protected]>2004-09-22 19:22:16 +0000
commitc4fcffe436fbfb5b0f3b7be2e5ee103ec74932f7 (patch)
tree7c9439ab1d9f5a4fd61bd57c755069007b23e0b6 /src/jake2/server/SV_SEND.java
parentbcb4ac6eefb425d5b0a90009da506361d5739e75 (diff)
major refactoring in game, server and client package
Diffstat (limited to 'src/jake2/server/SV_SEND.java')
-rw-r--r--src/jake2/server/SV_SEND.java266
1 files changed, 130 insertions, 136 deletions
diff --git a/src/jake2/server/SV_SEND.java b/src/jake2/server/SV_SEND.java
index 9b30a99..8488954 100644
--- a/src/jake2/server/SV_SEND.java
+++ b/src/jake2/server/SV_SEND.java
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 17.01.2004 by RST.
-// $Id: SV_SEND.java,v 1.5 2004-09-10 19:02:56 salomo Exp $
+// $Id: SV_SEND.java,v 1.6 2004-09-22 19:22:12 salomo Exp $
package jake2.server;
@@ -30,8 +30,9 @@ import jake2.client.*;
import jake2.game.*;
import jake2.qcommon.*;
import jake2.render.*;
+import jake2.util.Math3D;
-public class SV_SEND extends SV_MAIN {
+public class SV_SEND {
/*
=============================================================================
@@ -40,20 +41,19 @@ public class SV_SEND extends SV_MAIN {
=============================================================================
*/
- public static byte sv_outputbuf[]= new byte[SV_OUTPUTBUF_LENGTH];
+ public static byte sv_outputbuf[] = new byte[Defines.SV_OUTPUTBUF_LENGTH];
public static void SV_FlushRedirect(int sv_redirected, byte outputbuf[]) {
- if (sv_redirected == RD_PACKET) {
- String s= ("print\n" + outputbuf);
- Netchan.Netchan_OutOfBand(NS_SERVER, Netchan.net_from, s.length(), s.getBytes());
+ if (sv_redirected == Defines.RD_PACKET) {
+ String s = ("print\n" + outputbuf);
+ Netchan.Netchan_OutOfBand(Defines.NS_SERVER, Globals.net_from, s.length(), s.getBytes());
}
- else if (sv_redirected == RD_CLIENT) {
- MSG.WriteByte(SV_MAIN.sv_client.netchan.message, svc_print);
- MSG.WriteByte(SV_MAIN.sv_client.netchan.message, PRINT_HIGH);
+ else if (sv_redirected == Defines.RD_CLIENT) {
+ MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_print);
+ MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.PRINT_HIGH);
MSG.WriteString(SV_MAIN.sv_client.netchan.message, outputbuf);
- }
+ }
}
-
/*
=============================================================================
@@ -74,11 +74,10 @@ public class SV_SEND extends SV_MAIN {
if (level < cl.messagelevel)
return;
- MSG.WriteByte(cl.netchan.message, svc_print);
+ MSG.WriteByte(cl.netchan.message, Defines.svc_print);
MSG.WriteByte(cl.netchan.message, level);
MSG.WriteString(cl.netchan.message, s);
}
-
/*
=================
SV_BroadcastPrintf
@@ -91,23 +90,22 @@ public class SV_SEND extends SV_MAIN {
client_t cl;
// echo to console
- if (dedicated.value != 0) {
+ if (Globals.dedicated.value != 0) {
Com.Printf(s);
}
- for (int i= 0; i < SV_MAIN.maxclients.value; i++) {
- cl= SV_MAIN.svs.clients[i];
+ for (int i = 0; i < SV_MAIN.maxclients.value; i++) {
+ cl = SV_INIT.svs.clients[i];
if (level < cl.messagelevel)
continue;
- if (cl.state != cs_spawned)
+ if (cl.state != Defines.cs_spawned)
continue;
- MSG.WriteByte(cl.netchan.message, svc_print);
+ MSG.WriteByte(cl.netchan.message, Defines.svc_print);
MSG.WriteByte(cl.netchan.message, level);
MSG.WriteString(cl.netchan.message, s);
}
}
-
/*
=================
SV_BroadcastCommand
@@ -117,14 +115,13 @@ public class SV_SEND extends SV_MAIN {
*/
public static void SV_BroadcastCommand(String s) {
- if (sv.state == 0)
+ if (SV_INIT.sv.state == 0)
return;
- MSG.WriteByte(sv.multicast, svc_stufftext);
- MSG.WriteString(sv.multicast, s);
- SV_Multicast(null, MULTICAST_ALL_R);
+ MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_stufftext);
+ MSG.WriteString(SV_INIT.sv.multicast, s);
+ SV_Multicast(null, Defines.MULTICAST_ALL_R);
}
-
/*
=================
SV_Multicast
@@ -145,63 +142,63 @@ public class SV_SEND extends SV_MAIN {
boolean reliable;
int area1, area2;
- reliable= false;
+ reliable = false;
- if (to != MULTICAST_ALL_R && to != MULTICAST_ALL) {
- leafnum= CM.CM_PointLeafnum(origin);
- area1= CM.CM_LeafArea(leafnum);
+ if (to != Defines.MULTICAST_ALL_R && to != Defines.MULTICAST_ALL) {
+ leafnum = CM.CM_PointLeafnum(origin);
+ area1 = CM.CM_LeafArea(leafnum);
}
else {
- leafnum= 0; // just to avoid compiler warnings
- area1= 0;
+ leafnum = 0; // just to avoid compiler warnings
+ area1 = 0;
}
// if doing a serverrecord, store everything
- if (svs.demofile != null)
- SZ.Write(svs.demo_multicast, sv.multicast.data, sv.multicast.cursize);
+ if (SV_INIT.svs.demofile != null)
+ SZ.Write(SV_INIT.svs.demo_multicast, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize);
switch (to) {
- case MULTICAST_ALL_R :
- reliable= true; // intentional fallthrough, no break here
- case MULTICAST_ALL :
- leafnum= 0;
- mask= null;
+ case Defines.MULTICAST_ALL_R :
+ reliable = true; // intentional fallthrough, no break here
+ case Defines.MULTICAST_ALL :
+ leafnum = 0;
+ mask = null;
break;
- case MULTICAST_PHS_R :
- reliable= true; // intentional fallthrough
- case MULTICAST_PHS :
- leafnum= CM.CM_PointLeafnum(origin);
- cluster= CM.CM_LeafCluster(leafnum);
- mask= CM.CM_ClusterPHS(cluster);
+ case Defines.MULTICAST_PHS_R :
+ reliable = true; // intentional fallthrough
+ case Defines.MULTICAST_PHS :
+ leafnum = CM.CM_PointLeafnum(origin);
+ cluster = CM.CM_LeafCluster(leafnum);
+ mask = CM.CM_ClusterPHS(cluster);
break;
- case MULTICAST_PVS_R :
- reliable= true; // intentional fallthrough
- case MULTICAST_PVS :
- leafnum= CM.CM_PointLeafnum(origin);
- cluster= CM.CM_LeafCluster(leafnum);
- mask= CM.CM_ClusterPVS(cluster);
+ case Defines.MULTICAST_PVS_R :
+ reliable = true; // intentional fallthrough
+ case Defines.MULTICAST_PVS :
+ leafnum = CM.CM_PointLeafnum(origin);
+ cluster = CM.CM_LeafCluster(leafnum);
+ mask = CM.CM_ClusterPVS(cluster);
break;
default :
- mask= null;
- Com.Error(ERR_FATAL, "SV_Multicast: bad to:" + to + "\n");
+ mask = null;
+ Com.Error(Defines.ERR_FATAL, "SV_Multicast: bad to:" + to + "\n");
}
// send the data to all relevent clients
- for (j= 0; j < maxclients.value; j++) {
- client= svs.clients[j];
+ for (j = 0; j < SV_MAIN.maxclients.value; j++) {
+ client = SV_INIT.svs.clients[j];
- if (client.state == cs_free || client.state == cs_zombie)
+ if (client.state == Defines.cs_free || client.state == Defines.cs_zombie)
continue;
- if (client.state != cs_spawned && !reliable)
+ if (client.state != Defines.cs_spawned && !reliable)
continue;
if (mask != null) {
- leafnum= CM.CM_PointLeafnum(client.edict.s.origin);
- cluster= CM.CM_LeafCluster(leafnum);
- area2= CM.CM_LeafArea(leafnum);
+ leafnum = CM.CM_PointLeafnum(client.edict.s.origin);
+ cluster = CM.CM_LeafCluster(leafnum);
+ area2 = CM.CM_LeafArea(leafnum);
if (!CM.CM_AreasConnected(area1, area2))
continue;
@@ -213,14 +210,13 @@ public class SV_SEND extends SV_MAIN {
}
if (reliable)
- SZ.Write(client.netchan.message, sv.multicast.data, sv.multicast.cursize);
+ SZ.Write(client.netchan.message, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize);
else
- SZ.Write(client.datagram, sv.multicast.data, sv.multicast.cursize);
+ SZ.Write(client.datagram, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize);
}
- SZ.Clear(sv.multicast);
+ SZ.Clear(SV_INIT.sv.multicast);
}
-
/*
==================
SV_StartSound
@@ -259,98 +255,97 @@ public class SV_SEND extends SV_MAIN {
int flags;
int i;
int ent;
- float[] origin_v= { 0, 0, 0 };
+ float[] origin_v = { 0, 0, 0 };
boolean use_phs;
if (volume < 0 || volume > 1.0)
- Com.Error(ERR_FATAL, "SV_StartSound: volume = " + volume);
+ Com.Error(Defines.ERR_FATAL, "SV_StartSound: volume = " + volume);
if (attenuation < 0 || attenuation > 4)
- Com.Error(ERR_FATAL, "SV_StartSound: attenuation = " + attenuation);
+ Com.Error(Defines.ERR_FATAL, "SV_StartSound: attenuation = " + attenuation);
// if (channel < 0 || channel > 15)
// Com_Error (ERR_FATAL, "SV_StartSound: channel = %i", channel);
if (timeofs < 0 || timeofs > 0.255)
- Com.Error(ERR_FATAL, "SV_StartSound: timeofs = " + timeofs);
+ Com.Error(Defines.ERR_FATAL, "SV_StartSound: timeofs = " + timeofs);
- ent= entity.index;
+ ent = entity.index;
// no PHS flag
if ((channel & 8) != 0) {
- use_phs= false;
+ use_phs = false;
channel &= 7;
}
else
- use_phs= true;
+ use_phs = true;
- sendchan= (ent << 3) | (channel & 7);
+ sendchan = (ent << 3) | (channel & 7);
- flags= 0;
+ flags = 0;
if (volume != Defines.DEFAULT_SOUND_PACKET_VOLUME)
- flags |= SND_VOLUME;
- if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION)
- flags |= SND_ATTENUATION;
+ flags |= Defines.SND_VOLUME;
+ if (attenuation != Defines.DEFAULT_SOUND_PACKET_ATTENUATION)
+ flags |= Defines.SND_ATTENUATION;
// the client doesn't know that bmodels have weird origins
// the origin can also be explicitly set
- if ((entity.svflags & SVF_NOCLIENT) != 0 || (entity.solid == SOLID_BSP) || origin != null)
- flags |= SND_POS;
+ if ((entity.svflags & Defines.SVF_NOCLIENT) != 0 || (entity.solid == Defines.SOLID_BSP) || origin != null)
+ flags |= Defines.SND_POS;
// always send the entity number for channel overrides
- flags |= SND_ENT;
+ flags |= Defines.SND_ENT;
if (timeofs != 0)
- flags |= SND_OFFSET;
+ flags |= Defines.SND_OFFSET;
// use the entity origin unless it is a bmodel or explicitly specified
if (origin == null) {
- origin= origin_v;
- if (entity.solid == SOLID_BSP) {
- for (i= 0; i < 3; i++)
- origin_v[i]= entity.s.origin[i] + 0.5f * (entity.mins[i] + entity.maxs[i]);
+ origin = origin_v;
+ if (entity.solid == Defines.SOLID_BSP) {
+ for (i = 0; i < 3; i++)
+ origin_v[i] = entity.s.origin[i] + 0.5f * (entity.mins[i] + entity.maxs[i]);
}
else {
- VectorCopy(entity.s.origin, origin_v);
+ Math3D.VectorCopy(entity.s.origin, origin_v);
}
}
- MSG.WriteByte(sv.multicast, svc_sound);
- MSG.WriteByte(sv.multicast, flags);
- MSG.WriteByte(sv.multicast, soundindex);
+ MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_sound);
+ MSG.WriteByte(SV_INIT.sv.multicast, flags);
+ MSG.WriteByte(SV_INIT.sv.multicast, soundindex);
- if ((flags & SND_VOLUME) != 0)
- MSG.WriteByte(sv.multicast, volume * 255);
- if ((flags & SND_ATTENUATION) != 0)
- MSG.WriteByte(sv.multicast, attenuation * 64);
- if ((flags & SND_OFFSET) != 0)
- MSG.WriteByte(sv.multicast, timeofs * 1000);
+ if ((flags & Defines.SND_VOLUME) != 0)
+ MSG.WriteByte(SV_INIT.sv.multicast, volume * 255);
+ if ((flags & Defines.SND_ATTENUATION) != 0)
+ MSG.WriteByte(SV_INIT.sv.multicast, attenuation * 64);
+ if ((flags & Defines.SND_OFFSET) != 0)
+ MSG.WriteByte(SV_INIT.sv.multicast, timeofs * 1000);
- if ((flags & SND_ENT) != 0)
- MSG.WriteShort(sv.multicast, sendchan);
+ if ((flags & Defines.SND_ENT) != 0)
+ MSG.WriteShort(SV_INIT.sv.multicast, sendchan);
- if ((flags & SND_POS) != 0)
- MSG.WritePos(sv.multicast, origin);
+ if ((flags & Defines.SND_POS) != 0)
+ MSG.WritePos(SV_INIT.sv.multicast, origin);
// if the sound doesn't attenuate,send it to everyone
// (global radio chatter, voiceovers, etc)
- if (attenuation == ATTN_NONE)
- use_phs= false;
+ if (attenuation == Defines.ATTN_NONE)
+ use_phs = false;
- if ((channel & CHAN_RELIABLE) != 0) {
+ if ((channel & Defines.CHAN_RELIABLE) != 0) {
if (use_phs)
- SV_Multicast(origin, MULTICAST_PHS_R);
+ SV_Multicast(origin, Defines.MULTICAST_PHS_R);
else
- SV_Multicast(origin, MULTICAST_ALL_R);
+ SV_Multicast(origin, Defines.MULTICAST_ALL_R);
}
else {
if (use_phs)
- SV_Multicast(origin, MULTICAST_PHS);
+ SV_Multicast(origin, Defines.MULTICAST_PHS);
else
- SV_Multicast(origin, MULTICAST_ALL);
+ SV_Multicast(origin, Defines.MULTICAST_ALL);
}
}
-
/*
===============================================================================
@@ -365,17 +360,17 @@ public class SV_SEND extends SV_MAIN {
=======================
*/
public static boolean SV_SendClientDatagram(client_t client) {
- byte msg_buf[]= new byte[MAX_MSGLEN];
- sizebuf_t msg= new sizebuf_t();
+ byte msg_buf[] = new byte[Defines.MAX_MSGLEN];
+ sizebuf_t msg = new sizebuf_t();
SV_ENTS.SV_BuildClientFrame(client);
SZ.Init(msg, msg_buf, msg_buf.length);
- msg.allowoverflow= true;
+ msg.allowoverflow = true;
// send over all the relevant entity_state_t
// and the player_state_t
- SV_CCMDS.SV_WriteFrameToClient(client, msg);
+ SV_ENTS.SV_WriteFrameToClient(client, msg);
// copy the accumulated multicast datagram
// for this client out to the message
@@ -396,29 +391,27 @@ public class SV_SEND extends SV_MAIN {
Netchan.Transmit(client.netchan, msg.cursize, msg.data);
// record the size for rate estimation
- client.message_size[sv.framenum % RATE_MESSAGES]= msg.cursize;
+ client.message_size[SV_INIT.sv.framenum % Defines.RATE_MESSAGES] = msg.cursize;
return true;
}
-
/*
==================
SV_DemoCompleted
==================
*/
public static void SV_DemoCompleted() {
- if (sv.demofile != null) {
+ if (SV_INIT.sv.demofile != null) {
try {
- sv.demofile.close();
+ SV_INIT.sv.demofile.close();
}
catch (IOException e) {
Com.Printf("IOError closing d9emo fiele:" + e);
}
- sv.demofile= null;
+ SV_INIT.sv.demofile = null;
}
- SV_ENTS.SV_Nextserver();
+ SV_USER.SV_Nextserver();
}
-
/*
=======================
SV_RateDrop
@@ -432,24 +425,23 @@ public class SV_SEND extends SV_MAIN {
int i;
// never drop over the loopback
- if (c.netchan.remote_address.type == NA_LOOPBACK)
+ if (c.netchan.remote_address.type == Defines.NA_LOOPBACK)
return false;
- total= 0;
+ total = 0;
- for (i= 0; i < RATE_MESSAGES; i++) {
+ for (i = 0; i < Defines.RATE_MESSAGES; i++) {
total += c.message_size[i];
}
if (total > c.rate) {
c.surpressCount++;
- c.message_size[sv.framenum % RATE_MESSAGES]= 0;
+ c.message_size[SV_INIT.sv.framenum % Defines.RATE_MESSAGES] = 0;
return true;
}
return false;
}
-
/*
=======================
SV_SendClientMessages
@@ -459,20 +451,20 @@ public class SV_SEND extends SV_MAIN {
int i;
client_t c;
int msglen;
- byte msgbuf[]= new byte[MAX_MSGLEN];
+ byte msgbuf[] = new byte[Defines.MAX_MSGLEN];
int r;
- msglen= 0;
+ msglen = 0;
// read the next demo message if needed
- if (sv.state == ss_demo && sv.demofile != null) {
- if (sv_paused.value != 0)
- msglen= 0;
+ if (SV_INIT.sv.state == Defines.ss_demo && SV_INIT.sv.demofile != null) {
+ if (SV_MAIN.sv_paused.value != 0)
+ msglen = 0;
else {
// get the next message
//r = fread (&msglen, 4, 1, sv.demofile);
try {
- msglen= EndianHandler.swapInt(sv.demofile.readInt());
+ msglen = EndianHandler.swapInt(SV_INIT.sv.demofile.readInt());
}
catch (Exception e) {
SV_DemoCompleted();
@@ -484,13 +476,13 @@ public class SV_SEND extends SV_MAIN {
SV_DemoCompleted();
return;
}
- if (msglen > MAX_MSGLEN)
- Com.Error(ERR_DROP, "SV_SendClientMessages: msglen > MAX_MSGLEN");
+ if (msglen > Defines.MAX_MSGLEN)
+ Com.Error(Defines.ERR_DROP, "SV_SendClientMessages: msglen > MAX_MSGLEN");
//r = fread (msgbuf, msglen, 1, sv.demofile);
- r= 0;
+ r = 0;
try {
- r= sv.demofile.read(msgbuf, 0, msglen);
+ r = SV_INIT.sv.demofile.read(msgbuf, 0, msglen);
}
catch (IOException e1) {
Com.Printf("IOError: reading demo file, " + e1);
@@ -503,8 +495,8 @@ public class SV_SEND extends SV_MAIN {
}
// send a message to each connected client
- for (i= 0; i < maxclients.value; i++) {
- c= svs.clients[i];
+ for (i = 0; i < SV_MAIN.maxclients.value; i++) {
+ c = SV_INIT.svs.clients[i];
if (c.state == 0)
continue;
@@ -513,13 +505,15 @@ public class SV_SEND extends SV_MAIN {
if (c.netchan.message.overflowed) {
SZ.Clear(c.netchan.message);
SZ.Clear(c.datagram);
- SV_BroadcastPrintf(PRINT_HIGH, c.name + " overflowed\n");
- SV_DropClient(c);
+ SV_BroadcastPrintf(Defines.PRINT_HIGH, c.name + " overflowed\n");
+ SV_MAIN.SV_DropClient(c);
}
- if (sv.state == ss_cinematic || sv.state == ss_demo || sv.state == ss_pic)
+ if (SV_INIT.sv.state == Defines.ss_cinematic
+ || SV_INIT.sv.state == Defines.ss_demo
+ || SV_INIT.sv.state == Defines.ss_pic)
Netchan.Transmit(c.netchan, msglen, msgbuf);
- else if (c.state == cs_spawned) {
+ else if (c.state == Defines.cs_spawned) {
// don't overrun bandwidth
if (SV_RateDrop(c))
continue;