Update of /cvsroot/jake2/jake2/src/jake2/qcommon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11556/src/jake2/qcommon Modified Files: Cvar.java PMove.java Netchan.java Cbuf.java CM.java MSG.java netchan_t.java Q2DataDialog.java Log Message: major refactoring in game, server and client package Index: Q2DataDialog.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/Q2DataDialog.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Q2DataDialog.java 21 Sep 2004 12:52:14 -0000 1.6 --- Q2DataDialog.java 22 Sep 2004 19:22:09 -0000 1.7 *************** *** 1,427 **** ! /* ! * Q2DataDialog.java ! * ! * Created on 17. September 2004, 20:13 ! */ ! ! package jake2.qcommon; ! ! import java.awt.*; ! import java.io.*; ! import java.net.URL; ! import java.net.URLConnection; ! import java.util.Enumeration; ! import java.util.zip.ZipEntry; ! import java.util.zip.ZipFile; ! ! import javax.swing.*; ! ! /** ! * ! * @author hoz ! */ ! public class Q2DataDialog extends javax.swing.JDialog { ! ! /** Creates new form Q2DataDialog */ ! public Q2DataDialog() { ! super(); ! initComponents(); ! ! DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode(); ! int x = (mode.getWidth() - getWidth()) / 2; ! int y = (mode.getHeight() - getHeight()) / 2; ! setLocation(x, y); ! dir = System.getProperty("user.home") + "/jake2"; ! jTextField1.setText(dir); ! } ! ! /** This method is called from within the constructor to ! * initialize the form. ! * WARNING: Do NOT modify this code. The content of this method is ! * always regenerated by the Form Editor. ! */ ! private void initComponents() {//GEN-BEGIN:initComponents ! java.awt.GridBagConstraints gridBagConstraints; ! ! choosePanel = new javax.swing.JPanel(); ! statusPanel = new JPanel(); ! status = new JLabel("initializing Jake2..."); ! jTextField1 = new javax.swing.JTextField(); ! changeButton = new javax.swing.JButton(); ! installButton = new javax.swing.JButton(); ! exitButton = new javax.swing.JButton(); ! okButton = new javax.swing.JButton(); ! ! setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); ! setTitle("Jake2 - Bytonic Software"); ! ! setResizable(false); ! addWindowListener(new java.awt.event.WindowAdapter() { ! public void windowClosing(java.awt.event.WindowEvent evt) { ! formWindowClosing(evt); ! } ! }); ! ! choosePanel.setLayout(new java.awt.GridBagLayout()); ! ! choosePanel.setMaximumSize(new java.awt.Dimension(400, 100)); ! choosePanel.setMinimumSize(new java.awt.Dimension(400, 100)); ! choosePanel.setPreferredSize(new java.awt.Dimension(400, 100)); ! jTextField1.setPreferredSize(null); ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.gridwidth = 2; ! gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.weightx = 1.0; ! choosePanel.add(jTextField1, gridBagConstraints); ! ! changeButton.setText("change"); ! changeButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! changeButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 2; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; ! choosePanel.add(changeButton, gridBagConstraints); ! ! installButton.setText("Install"); ! installButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! installButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 1; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; ! choosePanel.add(installButton, gridBagConstraints); ! ! exitButton.setText("Exit"); ! exitButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! exitButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 1; ! gridBagConstraints.gridy = 1; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! choosePanel.add(exitButton, gridBagConstraints); ! ! okButton.setText("OK"); ! okButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! okButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 2; ! gridBagConstraints.gridy = 1; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; ! choosePanel.add(okButton, gridBagConstraints); ! ! //getContentPane().add(choosePanel, java.awt.BorderLayout.SOUTH); ! ! Jake2Canvas c = new Jake2Canvas(); ! getContentPane().add(c, BorderLayout.CENTER); ! ! statusPanel.setLayout(new java.awt.GridBagLayout()); ! statusPanel.setMaximumSize(new java.awt.Dimension(400, 100)); ! statusPanel.setMinimumSize(new java.awt.Dimension(400, 100)); ! statusPanel.setPreferredSize(new java.awt.Dimension(400, 100)); ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.gridwidth = 1; ! gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.weightx = 1.0; ! statusPanel.add(status, gridBagConstraints); ! getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH); ! ! installPanel = new InstallPanel(this); ! ! pack(); ! }//GEN-END:initComponents ! ! ! private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed ! dir = jTextField1.getText(); ! showInstallPanel(); ! installPanel.destDir = dir; ! ! dir += "/baseq2"; ! jTextField1.setText(dir); ! ! new Thread(installPanel).start(); ! }//GEN-LAST:event_installButtonActionPerformed ! ! private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed ! System.exit(1); ! dispose(); ! }//GEN-LAST:event_exitButtonActionPerformed ! ! private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed ! ! dir = jTextField1.getText(); ! Cvar.Set("cddir", dir); ! FS.setCDDir(); ! ! synchronized(this) { ! notifyAll(); ! } ! }//GEN-LAST:event_okButtonActionPerformed ! ! private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed ! JFileChooser chooser = new JFileChooser(); ! chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); ! chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); ! chooser.setMultiSelectionEnabled(false); ! chooser.setDialogTitle("choose a valid baseq2 directory"); ! chooser.showDialog(this, "OK"); ! ! dir = null; ! try { ! dir = chooser.getSelectedFile().getCanonicalPath(); ! } catch (IOException e) {} ! jTextField1.setText(dir); ! ! }//GEN-LAST:event_changeButtonActionPerformed ! ! private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing ! System.exit(1); ! dispose(); ! }//GEN-LAST:event_formWindowClosing ! ! // Variables declaration - do not modify//GEN-BEGIN:variables ! private javax.swing.JButton changeButton; ! private javax.swing.JButton exitButton; ! private javax.swing.JButton installButton; ! private Jake2Canvas canvas; ! private javax.swing.JPanel choosePanel; ! private JPanel statusPanel; ! private InstallPanel installPanel; ! private JLabel status; ! private javax.swing.JTextField jTextField1; ! private javax.swing.JButton okButton; ! // End of variables declaration//GEN-END:variables ! ! private String dir; ! ! void showChooseDialog() { ! getContentPane().remove(statusPanel); ! getContentPane().remove(installPanel); ! getContentPane().add(choosePanel, BorderLayout.SOUTH); ! validate(); ! repaint(); ! } ! ! void showStatus() { ! getContentPane().remove(choosePanel); ! getContentPane().add(statusPanel, BorderLayout.SOUTH); ! validate(); ! repaint(); ! } ! ! void showInstallPanel() { ! getContentPane().remove(choosePanel); ! getContentPane().add(installPanel, BorderLayout.SOUTH); ! validate(); ! repaint(); ! } ! ! void setStatus(String text) { ! status.setText(text); ! } ! ! void testQ2Data() { ! while (FS.LoadFile("pics/colormap.pcx") == null) { ! showChooseDialog(); ! ! try { ! synchronized(this) { ! wait(); ! } ! } catch (InterruptedException e) {} ! } ! showStatus(); ! repaint(); ! } ! ! static class Jake2Canvas extends Canvas { ! private Image image; ! Jake2Canvas() { ! setSize(400, 200); ! image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/splash.png")); ! while (!Toolkit.getDefaultToolkit().prepareImage(image, -1, -1, null)) { ! try { ! Thread.sleep(50); ! } catch (InterruptedException e) {} ! } ! } ! ! ! /* (non-Javadoc) ! * @see java.awt.Component#paint(java.awt.Graphics) ! */ ! public void paint(Graphics g) { ! g.drawImage(image, 0, 0, null); ! } ! ! } ! ! static class InstallPanel extends JPanel implements Runnable { ! ! static final String[] locs = { ! "ftp://ftp.fu-berlin.de/pc/msdos/games/idgames/idstuff/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.demon.co.uk/pub/mirrors/idsoftware/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.fragzone.se/pub/spel/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.idsoftware.com/idstuff/quake2/q2-314-demo-x86.exe" }; ! static byte[] buf = new byte[8192]; ! String destDir; ! ! JProgressBar progress = new JProgressBar(); ! JLabel label = new JLabel("test"); ! Q2DataDialog parent; ! ! public InstallPanel(Q2DataDialog d) { ! initComponents(); ! parent = d; ! } ! ! void initComponents() { ! progress.setMinimum(0); ! progress.setMaximum(100); ! setLayout(new GridBagLayout()); ! GridBagConstraints gridBagConstraints = new GridBagConstraints(); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.gridwidth = 1; ! gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.weightx = 1.0; ! gridBagConstraints.anchor = GridBagConstraints.SOUTH; ! add(label, gridBagConstraints); ! gridBagConstraints.gridy = 1; ! gridBagConstraints.anchor = GridBagConstraints.NORTH; ! add(progress, gridBagConstraints); ! Dimension d = new Dimension(400, 100); ! setMinimumSize(d); ! setMaximumSize(d); ! setPreferredSize(d); ! } ! ! public void run() { ! ! InputStream in = null; ! OutputStream out = null; ! File outFile = null; ! ! label.setText("downloading..."); ! ! File dir = null; ! try { ! dir = new File(destDir); ! dir.mkdirs(); ! } ! catch (Exception e) {} ! try { ! if (!dir.isDirectory() || !dir.canWrite()) return; ! } ! catch (Exception e) { ! return; ! } ! ! for (int i = 0; i < locs.length; i++) { ! try { ! URL url = new URL(locs[i]); ! URLConnection conn = url.openConnection(); ! int length = conn.getContentLength(); ! progress.setMaximum(length / 1024); ! ! in = conn.getInputStream(); ! ! outFile = File.createTempFile("Jake2Data", ".zip"); ! outFile.deleteOnExit(); ! out = new FileOutputStream(outFile); ! ! copyStream(in, out); ! break; ! } catch (Exception e) {} ! } ! try { ! installData(outFile.getCanonicalPath()); ! } catch (Exception e) {} ! ! ! try { ! if (outFile != null) outFile.delete(); ! } catch (Exception e) {} ! ! parent.showChooseDialog(); ! parent.okButtonActionPerformed(null); ! } ! ! ! void installData(String filename) { ! try { ! ZipFile f = new ZipFile(filename); ! Enumeration e = f.entries(); ! while (e.hasMoreElements()) { ! ZipEntry entry = (ZipEntry)e.nextElement(); ! String name = entry.getName(); ! int i; ! if ((i = name.indexOf("/baseq2")) > -1 && name.indexOf(".dll") == -1) { ! name = destDir + name.substring(i); ! File outFile = new File(name); ! if (entry.isDirectory()) { ! outFile.mkdirs(); ! } else { ! label.setText("installing " + outFile.getName()); ! progress.setMaximum((int)entry.getSize()/1024); ! progress.setValue(0); ! outFile.getParentFile().mkdirs(); ! OutputStream out = new FileOutputStream(outFile); ! InputStream in = f.getInputStream(entry); ! copyStream(in, out); ! } ! } ! } ! } catch (Exception e) {} ! } ! ! void copyStream(InputStream in, OutputStream out) { ! try { ! int c = 0; ! int l; ! while ((l = in.read(buf)) > 0) { ! out.write(buf, 0, l); ! c += l; ! progress.setValue(c / 1024); ! } ! } catch (Exception e) {} ! ! try { ! in.close(); ! } catch (Exception e) {} ! try { ! out.close(); ! } catch (Exception e) {} ! } ! } ! ! } --- 1,427 ---- ! /* ! * Q2DataDialog.java ! * ! * Created on 17. September 2004, 20:13 ! */ ! ! package jake2.qcommon; ! ! import java.awt.*; ! import java.io.*; ! import java.net.URL; ! import java.net.URLConnection; ! import java.util.Enumeration; ! import java.util.zip.ZipEntry; ! import java.util.zip.ZipFile; ! ! import javax.swing.*; ! ! /** ! * ! * @author hoz ! */ ! public class Q2DataDialog extends javax.swing.JDialog { ! ! /** Creates new form Q2DataDialog */ ! public Q2DataDialog() { ! super(); ! initComponents(); ! ! DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode(); ! int x = (mode.getWidth() - getWidth()) / 2; ! int y = (mode.getHeight() - getHeight()) / 2; ! setLocation(x, y); ! dir = System.getProperty("user.home") + "/jake2"; ! jTextField1.setText(dir); ! } ! ! /** This method is called from within the constructor to ! * initialize the form. ! * WARNING: Do NOT modify this code. The content of this method is ! * always regenerated by the Form Editor. ! */ ! private void initComponents() {//GEN-BEGIN:initComponents ! java.awt.GridBagConstraints gridBagConstraints; ! ! choosePanel = new javax.swing.JPanel(); ! statusPanel = new JPanel(); ! status = new JLabel("initializing Jake2..."); ! jTextField1 = new javax.swing.JTextField(); ! changeButton = new javax.swing.JButton(); ! installButton = new javax.swing.JButton(); ! exitButton = new javax.swing.JButton(); ! okButton = new javax.swing.JButton(); ! ! setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); ! setTitle("Jake2 - Bytonic Software"); ! ! setResizable(false); ! addWindowListener(new java.awt.event.WindowAdapter() { ! public void windowClosing(java.awt.event.WindowEvent evt) { ! formWindowClosing(evt); ! } ! }); ! ! choosePanel.setLayout(new java.awt.GridBagLayout()); ! ! choosePanel.setMaximumSize(new java.awt.Dimension(400, 100)); ! choosePanel.setMinimumSize(new java.awt.Dimension(400, 100)); ! choosePanel.setPreferredSize(new java.awt.Dimension(400, 100)); ! jTextField1.setPreferredSize(null); ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.gridwidth = 2; ! gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.weightx = 1.0; ! choosePanel.add(jTextField1, gridBagConstraints); ! ! changeButton.setText("change"); ! changeButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! changeButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 2; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; ! choosePanel.add(changeButton, gridBagConstraints); ! ! installButton.setText("Install"); ! installButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! installButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 1; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; ! choosePanel.add(installButton, gridBagConstraints); ! ! exitButton.setText("Exit"); ! exitButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! exitButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 1; ! gridBagConstraints.gridy = 1; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! choosePanel.add(exitButton, gridBagConstraints); ! ! okButton.setText("OK"); ! okButton.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! okButtonActionPerformed(evt); ! } ! }); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 2; ! gridBagConstraints.gridy = 1; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; ! choosePanel.add(okButton, gridBagConstraints); ! ! //getContentPane().add(choosePanel, java.awt.BorderLayout.SOUTH); ! ! Jake2Canvas c = new Jake2Canvas(); ! getContentPane().add(c, BorderLayout.CENTER); ! ! statusPanel.setLayout(new java.awt.GridBagLayout()); ! statusPanel.setMaximumSize(new java.awt.Dimension(400, 100)); ! statusPanel.setMinimumSize(new java.awt.Dimension(400, 100)); ! statusPanel.setPreferredSize(new java.awt.Dimension(400, 100)); ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.gridwidth = 1; ! gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.weightx = 1.0; ! statusPanel.add(status, gridBagConstraints); ! getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH); ! ! installPanel = new InstallPanel(this); ! ! pack(); ! }//GEN-END:initComponents ! ! ! private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed ! dir = jTextField1.getText(); ! showInstallPanel(); ! installPanel.destDir = dir; ! ! dir += "/baseq2"; ! jTextField1.setText(dir); ! ! new Thread(installPanel).start(); ! }//GEN-LAST:event_installButtonActionPerformed ! ! private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed ! System.exit(1); ! dispose(); ! }//GEN-LAST:event_exitButtonActionPerformed ! ! private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed ! ! dir = jTextField1.getText(); ! Cvar.Set("cddir", dir); ! FS.setCDDir(); ! ! synchronized(this) { ! notifyAll(); ! } ! }//GEN-LAST:event_okButtonActionPerformed ! ! private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed ! JFileChooser chooser = new JFileChooser(); ! chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); ! chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); ! chooser.setMultiSelectionEnabled(false); ! chooser.setDialogTitle("choose a valid baseq2 directory"); ! chooser.showDialog(this, "OK"); ! ! dir = null; ! try { ! dir = chooser.getSelectedFile().getCanonicalPath(); ! } catch (IOException e) {} ! jTextField1.setText(dir); ! ! }//GEN-LAST:event_changeButtonActionPerformed ! ! private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing ! System.exit(1); ! dispose(); ! }//GEN-LAST:event_formWindowClosing ! ! // Variables declaration - do not modify//GEN-BEGIN:variables ! private javax.swing.JButton changeButton; ! private javax.swing.JButton exitButton; ! private javax.swing.JButton installButton; ! private Jake2Canvas canvas; ! private javax.swing.JPanel choosePanel; ! private JPanel statusPanel; ! private InstallPanel installPanel; ! private JLabel status; ! private javax.swing.JTextField jTextField1; ! private javax.swing.JButton okButton; ! // End of variables declaration//GEN-END:variables ! ! private String dir; ! ! void showChooseDialog() { ! getContentPane().remove(statusPanel); ! getContentPane().remove(installPanel); ! getContentPane().add(choosePanel, BorderLayout.SOUTH); ! validate(); ! repaint(); ! } ! ! void showStatus() { ! getContentPane().remove(choosePanel); ! getContentPane().add(statusPanel, BorderLayout.SOUTH); ! validate(); ! repaint(); ! } ! ! void showInstallPanel() { ! getContentPane().remove(choosePanel); ! getContentPane().add(installPanel, BorderLayout.SOUTH); ! validate(); ! repaint(); ! } ! ! void setStatus(String text) { ! status.setText(text); ! } ! ! void testQ2Data() { ! while (FS.LoadFile("pics/colormap.pcx") == null) { ! showChooseDialog(); ! ! try { ! synchronized(this) { ! wait(); ! } ! } catch (InterruptedException e) {} ! } ! showStatus(); ! repaint(); ! } ! ! static class Jake2Canvas extends Canvas { ! private Image image; ! Jake2Canvas() { ! setSize(400, 200); ! image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/splash.png")); ! while (!Toolkit.getDefaultToolkit().prepareImage(image, -1, -1, null)) { ! try { ! Thread.sleep(50); ! } catch (InterruptedException e) {} ! } ! } ! ! ! /* (non-Javadoc) ! * @see java.awt.Component#paint(java.awt.Graphics) ! */ ! public void paint(Graphics g) { ! g.drawImage(image, 0, 0, null); ! } ! ! } ! ! static class InstallPanel extends JPanel implements Runnable { ! ! static final String[] locs = { ! "ftp://ftp.fu-berlin.de/pc/msdos/games/idgames/idstuff/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.demon.co.uk/pub/mirrors/idsoftware/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.fragzone.se/pub/spel/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.idsoftware.com/idstuff/quake2/q2-314-demo-x86.exe" }; ! static byte[] buf = new byte[8192]; ! String destDir; ! ! JProgressBar progress = new JProgressBar(); ! JLabel label = new JLabel("test"); ! Q2DataDialog parent; ! ! public InstallPanel(Q2DataDialog d) { ! initComponents(); ! parent = d; ! } ! ! void initComponents() { ! progress.setMinimum(0); ! progress.setMaximum(100); ! setLayout(new GridBagLayout()); ! GridBagConstraints gridBagConstraints = new GridBagConstraints(); ! ! gridBagConstraints = new java.awt.GridBagConstraints(); ! gridBagConstraints.gridx = 0; ! gridBagConstraints.gridy = 0; ! gridBagConstraints.gridwidth = 1; ! gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; ! gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); ! gridBagConstraints.weightx = 1.0; ! gridBagConstraints.anchor = GridBagConstraints.SOUTH; ! add(label, gridBagConstraints); ! gridBagConstraints.gridy = 1; ! gridBagConstraints.anchor = GridBagConstraints.NORTH; ! add(progress, gridBagConstraints); ! Dimension d = new Dimension(400, 100); ! setMinimumSize(d); ! setMaximumSize(d); ! setPreferredSize(d); ! } ! ! public void run() { ! ! InputStream in = null; ! OutputStream out = null; ! File outFile = null; ! ! label.setText("downloading..."); ! ! File dir = null; ! try { ! dir = new File(destDir); ! dir.mkdirs(); ! } ! catch (Exception e) {} ! try { ! if (!dir.isDirectory() || !dir.canWrite()) return; ! } ! catch (Exception e) { ! return; ! } ! ! for (int i = 0; i < locs.length; i++) { ! try { ! URL url = new URL(locs[i]); ! URLConnection conn = url.openConnection(); ! int length = conn.getContentLength(); ! progress.setMaximum(length / 1024); ! ! in = conn.getInputStream(); ! ! outFile = File.createTempFile("Jake2Data", ".zip"); ! outFile.deleteOnExit(); ! out = new FileOutputStream(outFile); ! ! copyStream(in, out); ! break; ! } catch (Exception e) {} ! } ! try { ! installData(outFile.getCanonicalPath()); ! } catch (Exception e) {} ! ! ! try { ! if (outFile != null) outFile.delete(); ! } catch (Exception e) {} ! ! parent.showChooseDialog(); ! parent.okButtonActionPerformed(null); ! } ! ! ! void installData(String filename) { ! try { ! ZipFile f = new ZipFile(filename); ! Enumeration e = f.entries(); ! while (e.hasMoreElements()) { ! ZipEntry entry = (ZipEntry)e.nextElement(); ! String name = entry.getName(); ! int i; ! if ((i = name.indexOf("/baseq2")) > -1 && name.indexOf(".dll") == -1) { ! name = destDir + name.substring(i); ! File outFile = new File(name); ! if (entry.isDirectory()) { ! outFile.mkdirs(); ! } else { ! label.setText("installing " + outFile.getName()); ! progress.setMaximum((int)entry.getSize()/1024); ! progress.setValue(0); ! outFile.getParentFile().mkdirs(); ! OutputStream out = new FileOutputStream(outFile); ! InputStream in = f.getInputStream(entry); ! copyStream(in, out); ! } ! } ! } ! } catch (Exception e) {} ! } ! ! void copyStream(InputStream in, OutputStream out) { ! try { ! int c = 0; ! int l; ! while ((l = in.read(buf)) > 0) { ! out.write(buf, 0, l); ! c += l; ! progress.setValue(c / 1024); ! } ! } catch (Exception e) {} ! ! try { ! in.close(); ! } catch (Exception e) {} ! try { ! out.close(); ! } catch (Exception e) {} ! } ! } ! ! } Index: PMove.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/PMove.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PMove.java 10 Sep 2004 19:02:53 -0000 1.4 --- PMove.java 22 Sep 2004 19:22:09 -0000 1.5 *************** *** 1,25 **** /* ! Copyright (C) 1997-2001 Id Software, Inc. ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of [...2416 lines suppressed...] ! ! Math3D.VectorCopy(PMove.pm.viewangles, angles); ! if (angles[Defines.PITCH] > 180) ! angles[Defines.PITCH] = angles[Defines.PITCH] - 360; ! angles[Defines.PITCH] /= 3; ! ! Math3D.AngleVectors(angles, PMove.pml.forward, PMove.pml.right, ! PMove.pml.up); ! ! PMove.PM_AirMove(); ! } ! } ! ! // set groundentity, watertype, and waterlevel for final spot ! PMove.PM_CatagorizePosition(); ! ! PM_SnapPosition(); ! } ! } \ No newline at end of file Index: MSG.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/MSG.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MSG.java 28 Jul 2004 11:58:10 -0000 1.4 --- MSG.java 22 Sep 2004 19:22:09 -0000 1.5 *************** *** 1,562 **** /* ! Copyright (C) 1997-2001 Id Software, Inc. ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of [...1093 lines suppressed...] ! if ((bits & CM_BUTTONS) != 0) ! move.buttons = (byte) ReadByte(msg_read); ! if ((bits & CM_IMPULSE) != 0) ! move.impulse = (byte) ReadByte(msg_read); ! ! // read time to run command ! move.msec = (byte) ReadByte(msg_read); ! ! // read the light level ! move.lightlevel = (byte) ReadByte(msg_read); ! ! } ! ! public static void ReadData(sizebuf_t msg_read, byte data[], int len) { ! for (int i = 0; i < len; i++) ! data[i] = (byte) ReadByte(msg_read); ! } ! } \ No newline at end of file Index: Cbuf.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/Cbuf.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Cbuf.java 18 Sep 2004 13:07:46 -0000 1.4 --- Cbuf.java 22 Sep 2004 19:22:09 -0000 1.5 *************** *** 6,27 **** */ /* ! Copyright (C) 1997-2001 Id Software, Inc. ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! This program 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 General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ package jake2.qcommon; --- 6,27 ---- */ /* ! Copyright (C) 1997-2001 Id Software, Inc. ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! This program 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 General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ package jake2.qcommon; *************** *** 29,32 **** --- 29,33 ---- import jake2.Globals; import jake2.game.Cmd; + import jake2.util.Lib; /** *************** *** 35,246 **** public final class Cbuf { ! /** ! * ! */ ! public static void Init() { ! SZ.Init(Globals.cmd_text, Globals.cmd_text_buf, Globals.cmd_text_buf.length); ! } ! public static void InsertText(String text) { ! byte[] temp = null; ! int templen = 0; ! // copy off any commands still remaining in the exec buffer ! templen = Globals.cmd_text.cursize; ! if (templen != 0) { ! temp = new byte[templen]; ! System.arraycopy(Globals.cmd_text.data, 0, temp, 0, templen); ! SZ.Clear(Globals.cmd_text); ! } ! // add the entire text of the file ! Cbuf.AddText(text); ! // add the copied off data ! if (templen != 0) { ! SZ.Write(Globals.cmd_text, temp, templen); ! temp = null; ! } ! } ! /** ! * @param clear ! */ ! static void AddEarlyCommands(boolean clear) { ! for (int i = 0; i < Com.Argc(); i++) { ! String s = Com.Argv(i); ! if (!s.equals("+set")) ! continue; ! Cbuf.AddText("set " + Com.Argv(i + 1) + " " + Com.Argv(i + 2) + "\n"); ! if (clear) { ! Com.ClearArgv(i); ! Com.ClearArgv(i + 1); ! Com.ClearArgv(i + 2); ! } ! i += 2; ! } ! } ! /** ! * @return ! */ ! static boolean AddLateCommands() { ! int i; ! int j; ! boolean ret = false; ! // build the combined string to parse from ! int s = 0; ! int argc = Com.Argc(); ! for (i = 1; i < argc; i++) { ! s += Com.Argv(i).length(); ! } ! if (s == 0) ! return false; ! String text = ""; ! for (i = 1; i < argc; i++) { ! text += Com.Argv(i); ! if (i != argc - 1) ! text += " "; ! } ! // pull out the commands ! String build = ""; ! for (i = 0; i < text.length(); i++) { ! if (text.charAt(i) == '+') { ! i++; ! for (j = i;(text.charAt(j) != '+') && (text.charAt(j) != '-') && j < text.length(); j++); ! build += text.substring(i, j - 1); ! build += "\n"; ! i = j - 1; ! } ! } ! ret = (build.length() != 0); ! if (ret) ! Cbuf.AddText(build); ! text = null; ! build = null; ! return ret; ! } ! /** ! * @param text ! */ ! public static void AddText(String text) { ! int l = text.length(); ! if (Globals.cmd_text.cursize + l >= Globals.cmd_text.maxsize) { ! Com.Printf("Cbuf_AddText: overflow\n"); ! return; ! } ! SZ.Write(Globals.cmd_text, text.getBytes(), l); ! } ! /** ! * ! */ ! public static void Execute() { ! byte[] text = null; ! byte[] line = new byte[1024]; ! Globals.alias_count = 0; // don't allow infinite alias loops ! ! while (Globals.cmd_text.cursize != 0) { ! // find a \n or ; line break ! text = Globals.cmd_text.data; ! int quotes = 0; ! int i; ! for (i = 0; i < Globals.cmd_text.cursize; i++) { ! if (text[i] == '"') ! quotes++; ! if (!(quotes % 2 != 0) && text[i] == ';') ! break; // don't break if inside a quoted string ! if (text[i] == '\n') ! break; ! } ! System.arraycopy(text, 0, line, 0, i); ! line[i] = 0; ! // delete the text from the command buffer and move remaining commands down ! // this is necessary because commands (exec, alias) can insert data at the ! // beginning of the text buffer ! if (i == Globals.cmd_text.cursize) ! Globals.cmd_text.cursize = 0; ! else { ! i++; ! Globals.cmd_text.cursize -= i; ! byte[] tmp = new byte[Globals.cmd_text.cursize]; ! System.arraycopy(text, i, tmp, 0, Globals.cmd_text.cursize); ! System.arraycopy(tmp, 0, text, 0, Globals.cmd_text.cursize); ! text[Globals.cmd_text.cursize] = '\0'; ! } ! // execute the command line ! int len = jake2.util.Lib.strlen(line); ! String cmd = new String(line, 0, len); ! Cmd.ExecuteString(cmd); ! if (Globals.cmd_wait) { ! // skip out while text still remains in buffer, leaving it ! // for next frame ! Globals.cmd_wait = false; ! break; ! } ! } ! } ! public static void ExecuteText(int exec_when, String text) { ! switch(exec_when) { ! case Defines.EXEC_NOW: ! Cmd.ExecuteString(text); ! break; ! case Defines.EXEC_INSERT: ! Cbuf.InsertText(text); ! break; ! case Defines.EXEC_APPEND: ! Cbuf.AddText(text); ! break; ! default: ! Com.Error(Defines.ERR_FATAL, "Cbuf_ExecuteText: bad exec_when"); ! } ! } ! /* ! ============ ! Cbuf_CopyToDefer ! ============ ! */ ! public static void CopyToDefer() { ! System.arraycopy(Globals.cmd_text_buf, 0, Globals.defer_text_buf, 0, Globals.cmd_text.cursize); ! Globals.defer_text_buf[Globals.cmd_text.cursize] = 0; ! Globals.cmd_text.cursize = 0; ! } ! /* ! ============ ! Cbuf_InsertFromDefer ! ============ ! */ ! public static void InsertFromDefer() { ! InsertText(new String(Globals.defer_text_buf).trim()); ! Globals.defer_text_buf[0] = 0; ! } ! } --- 36,250 ---- public final class Cbuf { ! /** ! * ! */ ! public static void Init() { ! SZ.Init(Globals.cmd_text, Globals.cmd_text_buf, ! Globals.cmd_text_buf.length); ! } ! public static void InsertText(String text) { ! byte[] temp = null; ! int templen = 0; ! // copy off any commands still remaining in the exec buffer ! templen = Globals.cmd_text.cursize; ! if (templen != 0) { ! temp = new byte[templen]; ! System.arraycopy(Globals.cmd_text.data, 0, temp, 0, templen); ! SZ.Clear(Globals.cmd_text); ! } ! // add the entire text of the file ! Cbuf.AddText(text); ! // add the copied off data ! if (templen != 0) { ! SZ.Write(Globals.cmd_text, temp, templen); ! temp = null; ! } ! } ! /** ! * @param clear ! */ ! static void AddEarlyCommands(boolean clear) { ! for (int i = 0; i < Com.Argc(); i++) { ! String s = Com.Argv(i); ! if (!s.equals("+set")) ! continue; ! Cbuf.AddText("set " + Com.Argv(i + 1) + " " + Com.Argv(i + 2) ! + "\n"); ! if (clear) { ! Com.ClearArgv(i); ! Com.ClearArgv(i + 1); ! Com.ClearArgv(i + 2); ! } ! i += 2; ! } ! } ! /** ! * @return ! */ ! static boolean AddLateCommands() { ! int i; ! int j; ! boolean ret = false; ! // build the combined string to parse from ! int s = 0; ! int argc = Com.Argc(); ! for (i = 1; i < argc; i++) { ! s += Com.Argv(i).length(); ! } ! if (s == 0) ! return false; ! String text = ""; ! for (i = 1; i < argc; i++) { ! text += Com.Argv(i); ! if (i != argc - 1) ! text += " "; ! } ! // pull out the commands ! String build = ""; ! for (i = 0; i < text.length(); i++) { ! if (text.charAt(i) == '+') { ! i++; ! for (j = i; (text.charAt(j) != '+') && (text.charAt(j) != '-') ! && j < text.length(); j++) ! ; ! build += text.substring(i, j - 1); ! build += "\n"; ! i = j - 1; ! } ! } ! ret = (build.length() != 0); ! if (ret) ! Cbuf.AddText(build); ! text = null; ! build = null; ! return ret; ! } ! /** ! * @param text ! */ ! public static void AddText(String text) { ! int l = text.length(); ! if (Globals.cmd_text.cursize + l >= Globals.cmd_text.maxsize) { ! Com.Printf("Cbuf_AddText: overflow\n"); ! return; ! } ! SZ.Write(Globals.cmd_text, text.getBytes(), l); ! } ! /** ! * ! */ ! public static void Execute() { ! byte[] text = null; ! byte[] line = new byte[1024]; ! Globals.alias_count = 0; // don't allow infinite alias loops ! while (Globals.cmd_text.cursize != 0) { ! // find a \n or ; line break ! text = Globals.cmd_text.data; ! int quotes = 0; ! int i; ! for (i = 0; i < Globals.cmd_text.cursize; i++) { ! if (text[i] == '"') ! quotes++; ! if (!(quotes % 2 != 0) && text[i] == ';') ! break; // don't break if inside a quoted string ! if (text[i] == '\n') ! break; ! } ! System.arraycopy(text, 0, line, 0, i); ! line[i] = 0; ! // delete the text from the command buffer and move remaining ! // commands down ! // this is necessary because commands (exec, alias) can insert data ! // at the ! // beginning of the text buffer ! if (i == Globals.cmd_text.cursize) ! Globals.cmd_text.cursize = 0; ! else { ! i++; ! Globals.cmd_text.cursize -= i; ! byte[] tmp = new byte[Globals.cmd_text.cursize]; ! System.arraycopy(text, i, tmp, 0, Globals.cmd_text.cursize); ! System.arraycopy(tmp, 0, text, 0, Globals.cmd_text.cursize); ! text[Globals.cmd_text.cursize] = '\0'; ! } ! // execute the command line ! int len = Lib.strlen(line); ! String cmd = new String(line, 0, len); ! Cmd.ExecuteString(cmd); ! if (Globals.cmd_wait) { ! // skip out while text still remains in buffer, leaving it ! // for next frame ! Globals.cmd_wait = false; ! break; ! } ! } ! } ! public static void ExecuteText(int exec_when, String text) { ! switch (exec_when) { ! case Defines.EXEC_NOW: ! Cmd.ExecuteString(text); ! break; ! case Defines.EXEC_INSERT: ! Cbuf.InsertText(text); ! break; ! case Defines.EXEC_APPEND: ! Cbuf.AddText(text); ! break; ! default: ! Com.Error(Defines.ERR_FATAL, "Cbuf_ExecuteText: bad exec_when"); ! } ! } ! /* ! * ============ Cbuf_CopyToDefer ============ ! */ ! public static void CopyToDefer() { ! System.arraycopy(Globals.cmd_text_buf, 0, Globals.defer_text_buf, 0, ! Globals.cmd_text.cursize); ! Globals.defer_text_buf[Globals.cmd_text.cursize] = 0; ! Globals.cmd_text.cursize = 0; ! } ! /* ! * ============ Cbuf_InsertFromDefer ============ ! */ ! public static void InsertFromDefer() { ! InsertText(new String(Globals.defer_text_buf).trim()); ! Globals.defer_text_buf[0] = 0; ! } ! ! } \ No newline at end of file Index: CM.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/CM.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CM.java 28 Jul 2004 12:01:27 -0000 1.5 --- CM.java 22 Sep 2004 19:22:09 -0000 1.6 *************** *** 1,28 **** /* ! Copyright (C) 1997-2001 Id Software, Inc. ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of [...3784 lines suppressed...] ! int cluster; ! cnode_t node; ! ! if (nodenum < 0) { ! leafnum = -1 - nodenum; ! cluster = map_leafs[leafnum].cluster; ! if (cluster == -1) ! return false; ! if (0 != (visbits[cluster >>> 3] & (1 << (cluster & 7)))) ! return true; ! return false; ! } ! ! node = map_nodes[nodenum]; ! if (CM_HeadnodeVisible(node.children[0], visbits)) ! return true; ! return CM_HeadnodeVisible(node.children[1], visbits); ! } ! } \ No newline at end of file Index: netchan_t.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/netchan_t.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** netchan_t.java 7 Jul 2004 19:59:34 -0000 1.1.1.1 --- netchan_t.java 22 Sep 2004 19:22:09 -0000 1.2 *************** *** 1,79 **** /* ! Copyright (C) 1997-2001 Id Software, Inc. ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! This program 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 General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ ! // Created on 27.11.2003 by RST. ! // $Id$ ! package jake2.qcommon; ! import jake2.*; ! public class netchan_t { ! public boolean fatal_error; ! // was enum {NS_CLIENT, NS_SERVER} ! public int sock; ! public int dropped; // between last packet and previous ! public int last_received; // for timeouts ! public int last_sent; // for retransmits ! public netadr_t remote_address = new netadr_t(); ! public int qport; // qport value to write when transmitting ! // sequencing variables ! public int incoming_sequence; ! public int incoming_acknowledged; ! public int incoming_reliable_acknowledged; // single bit ! public int incoming_reliable_sequence; // single bit, maintained local ! public int outgoing_sequence; ! public int reliable_sequence; // single bit ! public int last_reliable_sequence; // sequence number of last send ! // reliable staging and holding areas ! public sizebuf_t message = new sizebuf_t(); // writing buffer to send to server ! public byte message_buf[] = new byte[Defines.MAX_MSGLEN - 16]; // leave space for header ! // message is copied to this buffer when it is first transfered ! int reliable_length; ! ! byte reliable_buf[] = new byte[Defines.MAX_MSGLEN - 16]; // unpcked reliable message ! //ok. ! public void clear() ! { ! sock=dropped=last_received=last_sent=0; ! remote_address = new netadr_t(); ! qport = incoming_sequence = incoming_acknowledged = incoming_reliable_acknowledged = incoming_reliable_sequence ! = outgoing_sequence = reliable_sequence = last_reliable_sequence =0; ! message = new sizebuf_t(); ! ! message_buf = new byte[Defines.MAX_MSGLEN - 16]; ! ! reliable_length =0; ! reliable_buf = new byte[Defines.MAX_MSGLEN - 16]; ! } ! ! } --- 1,87 ---- /* ! * Copyright (C) 1997-2001 Id Software, Inc. ! * ! * This program is free software; you can redistribute it and/or modify it under ! * the terms of the GNU General Public License as published by the Free Software ! * Foundation; either version 2 of the License, or (at your option) any later ! * version. ! * ! * This program 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 General Public License for more details. ! * ! * You should have received a copy of the GNU General Public License along with ! * this program; if not, write to the Free Software Foundation, Inc., 59 Temple ! * Place - Suite 330, Boston, MA 02111-1307, USA. ! * ! */ ! // Created on 27.11.2003 by RST. ! // $Id$ ! package jake2.qcommon; ! import jake2.*; ! public class netchan_t { ! public boolean fatal_error; ! // was enum {NS_CLIENT, NS_SERVER} ! public int sock; ! public int dropped; // between last packet and previous ! public int last_received; // for timeouts ! public int last_sent; // for retransmits ! public netadr_t remote_address = new netadr_t(); + public int qport; // qport value to write when transmitting ! // sequencing variables ! public int incoming_sequence; ! public int incoming_acknowledged; ! public int incoming_reliable_acknowledged; // single bit ! public int incoming_reliable_sequence; // single bit, maintained local ! public int outgoing_sequence; ! public int reliable_sequence; // single bit ! public int last_reliable_sequence; // sequence number of last send ! // reliable staging and holding areas ! public sizebuf_t message = new sizebuf_t(); // writing buffer to send to ! // server ! public byte message_buf[] = new byte[Defines.MAX_MSGLEN - 16]; // leave ! // space for ! // header ! // message is copied to this buffer when it is first transfered ! public int reliable_length; ! public byte reliable_buf[] = new byte[Defines.MAX_MSGLEN - 16]; // unpcked ! // reliable ! // message ! ! //ok. ! public void clear() { ! sock = dropped = last_received = last_sent = 0; ! remote_address = new netadr_t(); ! qport = incoming_sequence = incoming_acknowledged = incoming_reliable_acknowledged = incoming_reliable_sequence = outgoing_sequence = reliable_sequence = last_reliable_sequence = 0; ! message = new sizebuf_t(); ! ! message_buf = new byte[Defines.MAX_MSGLEN - 16]; ! ! reliable_length = 0; ! reliable_buf = new byte[Defines.MAX_MSGLEN - 16]; ! } ! ! } \ No newline at end of file Index: Netchan.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/Netchan.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Netchan.java 12 Jul 2004 20:47:00 -0000 1.3 --- Netchan.java 22 Sep 2004 19:22:09 -0000 1.4 *************** *** 6,27 **** */ /* ! Copyright (C) 1997-2001 Id Software, Inc. ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! This program 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 General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ package jake2.qcommon; --- 6,27 ---- */ /* ! Copyright (C) 1997-2001 Id Software, Inc. ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! This program 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 General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ package jake2.qcommon; *************** *** 38,386 **** public final class Netchan extends SV_MAIN { ! /* ! ! packet header ! ------------- ! 31 sequence ! 1 does this message contains a reliable payload ! 31 acknowledge sequence ! 1 acknowledge receipt of even/odd message ! 16 qport ! ! The remote connection never knows if it missed a reliable message, the ! local side detects that it has been dropped by seeing a sequence acknowledge ! higher thatn the last reliable sequence, but without the correct evon/odd ! bit for the reliable set. ! ! If the sender notices that a reliable message has been dropped, it will be ! retransmitted. It will not be retransmitted again until a message after ! the retransmit has been acknowledged and the reliable still failed to get there. ! ! if the sequence number is -1, the packet should be handled without a netcon ! ! The reliable message can be added to at any time by doing ! MSG_Write* (&netchan.message, <data>). ! ! If the message buffer is overflowed, either by a single message, or by ! multiple frames worth piling up while the last reliable transmit goes ! unacknowledged, the netchan signals a fatal error. ! ! Reliable messages are always placed first in a packet, then the unreliable ! message is included if there is sufficient room. ! ! To the receiver, there is no distinction between the reliable and unreliable ! parts of the message, they are just processed out as a single larger message. ! ! Illogical packet sequence numbers cause the packet to be dropped, but do ! not kill the connection. This, combined with the tight window of valid ! reliable acknowledgement numbers provides protection against malicious ! address spoofing. ! ! ! The qport field is a workaround for bad address translating routers that ! sometimes remap the client's source port on a packet during gameplay. ! ! If the base part of the net address matches and the qport matches, then the ! channel matches even if the IP port differs. The IP port should be updated ! to the new value before sending out any replies. ! ! ! If there is no information that needs to be transfered on a given frame, ! such as during the connection stage while waiting for the client to load, ! then a packet only needs to be delivered if there is something in the ! unacknowledged reliable ! */ ! public static cvar_t showpackets; ! public static cvar_t showdrop; ! public static cvar_t qport; ! //public static netadr_t net_from = new netadr_t(); ! public static sizebuf_t net_message = new sizebuf_t(); ! public static byte net_message_buffer[] = new byte[Defines.MAX_MSGLEN]; ! /* ! =============== ! Netchan_Init ! ! =============== ! */ ! //ok. ! public static void Netchan_Init() { ! long port; ! // pick a port value that should be nice and random ! port = Sys.Milliseconds() & 0xffff; ! showpackets = Cvar.Get("showpackets", "0", 0); ! showdrop = Cvar.Get("showdrop", "0", 0); ! qport = Cvar.Get("qport", "" + port, Defines.CVAR_NOSET); ! } ! /* ! =============== ! Netchan_OutOfBand ! ! Sends an out-of-band datagram ! ================ ! */ ! //ok. ! public static void Netchan_OutOfBand(int net_socket, netadr_t adr, int length, byte data[]) { ! sizebuf_t send = new sizebuf_t(); ! byte send_buf[] = new byte[Defines.MAX_MSGLEN]; ! // write the packet header ! SZ.Init(send, send_buf, Defines.MAX_MSGLEN); ! MSG.WriteInt(send, -1); // -1 sequence means out of band ! SZ.Write(send, data, length); ! // send the datagram ! NET.SendPacket(net_socket, send.cursize, send.data, adr); ! } ! ! public static void OutOfBandPrint(int net_socket, netadr_t adr, String s) { ! Netchan_OutOfBand(net_socket, adr, s.length(), s.getBytes()); ! } ! /* ! ============== ! Netchan_Setup ! ! called to open a channel to a remote system ! ============== ! */ ! public static void Setup(int sock, netchan_t chan, netadr_t adr, int qport) { ! //memset (chan, 0, sizeof(*chan)); ! chan.clear(); ! chan.sock = sock; ! chan.remote_address.set(adr); ! chan.qport = qport; ! chan.last_received = Globals.curtime; ! chan.incoming_sequence = 0; ! chan.outgoing_sequence = 1; ! SZ.Init(chan.message, chan.message_buf, chan.message_buf.length); ! chan.message.allowoverflow = true; ! } ! /* ! =============== ! Netchan_CanReliable ! ! Returns true if the last reliable message has acked ! ================ ! */ ! public static boolean Netchan_CanReliable(netchan_t chan) { ! if (chan.reliable_length != 0) ! return false; // waiting for ack ! return true; ! } ! // das ist richtig !!! ! public static boolean Netchan_NeedReliable(netchan_t chan) { ! boolean send_reliable; ! // if the remote side dropped the last reliable message, resend it ! send_reliable = false; ! if (chan.incoming_acknowledged > chan.last_reliable_sequence && chan.incoming_reliable_acknowledged != chan.reliable_sequence) ! send_reliable = true; ! // if the reliable transmit buffer is empty, copy the current message out ! if (0 == chan.reliable_length && chan.message.cursize != 0) { ! send_reliable = true; ! } ! return send_reliable; ! } ! /* ! =============== ! Netchan_Transmit ! ! tries to send an unreliable message to a connection, and handles the ! transmition / retransmition of the reliable messages. ! ! A 0 length will still generate a packet and deal with the reliable messages. ! ================ ! */ ! public static void Transmit(netchan_t chan, int length, byte data[]) { ! sizebuf_t send = new sizebuf_t(); ! byte send_buf[] = new byte[MAX_MSGLEN]; ! int send_reliable; ! int w1, w2; ! // check for message overflow ! if (chan.message.overflowed) { ! chan.fatal_error = true; ! Com.Printf(NET.AdrToString(chan.remote_address) + ":Outgoing message overflow\n"); ! return; ! } ! send_reliable = Netchan_NeedReliable(chan) ? 1 : 0; ! if (chan.reliable_length == 0 && chan.message.cursize != 0) { ! System.arraycopy(chan.message_buf, 0, chan.reliable_... [truncated message content] |