Two ships are now available, currently selected at random
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 25 Jun 2014 12:53:14 +0000 (12:53 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 25 Jun 2014 12:53:14 +0000 (12:53 +0000)
mmsoftware/mystic_ships/README
mmsoftware/mystic_ships/client/src/main.c
mmsoftware/mystic_ships/client/src/main.h
mmsoftware/mystic_ships/client/src/packets.c
mmsoftware/mystic_ships/common/packets_common.h
mmsoftware/mystic_ships/server/src/client.c
mmsoftware/mystic_ships/server/src/packets.c
mmsoftware/mystic_ships/server/src/packets.h
mmsoftware/mystic_ships/server/src/ships.c
mmsoftware/mystic_ships/server/src/ships.h

index ef0d54f..3e29175 100644 (file)
@@ -1,11 +1,12 @@
-$Id: README,v 1.1 2006/12/31 08:32:39 mmondor Exp $
+$Id: README,v 1.2 2014/06/25 12:53:13 mmondor Exp $
+
+Note that some of this text is outdated.
 
 TODO
 ====
 
 SERVER
 
-- Add support for collisions between torpedoes and ships.
 - Add support for multiframe objects.  For instance, detonations could have
   multiple frames, as well as the cloaking effect.  These should possibly more
   be time-dependent than actual frame dependent however, considering that
@@ -20,16 +21,8 @@ SERVER
 - Implement authentication credentials checking, limit same user to one
   connection only
 - Limit connections per ip address in number and frequency
-- Implement and test using rc4 or openssl with aes.  Verify if the overhead
-  is negligeable enough to be worth keeping.  Otherwise, we could use crypto-
-  graphy for authentication only if wanted.
-- Possibly implement as part of the authentication system a method to only
-  allow signed client keys, the client key would be sent to us, and then also
-  make sure that only one client using that key can connect at a time,
-  logging when it's not the case.  This client-specific unique signed key
-  could be used as ID possibly?  Or other than signing we perhaps should also
-  sign against the player's name and verify at login that he can only use that
-  login with that key, too.
+- Implement and test using openssl with aes.  Verify if the overhead
+  is negligeable enough to be worth keeping.
 - Add proper connection/disconnection/events logging
 
 CLIENT
@@ -42,10 +35,6 @@ CLIENT
   for messages from the server using a ring, since SDL events would
   automatically be queued meanwhile?
   Also now send user events to the server.
-- Add an auto-ping along with fps...  Use SDL_GetTicks() to calculate the
-  delay between sending ping and receiving pong.
-- Create packets to also send user updates about his ship's statistics.
-  These could probably be updated less frequently than 10 times per second.
 
 
 NOTES
@@ -74,7 +63,7 @@ unclear if windows supports this properly), a decision was made to
 port to SDL an inter-thread messaging library I had done for use
 with POSIX threads, and to use multiple threads.
 
-One thread will be used to send data to the server, another thread
+One thread is used to send data to the server, another thread
 to receive data form the server, yet another thread to deal with
 all user input events, and a main thread to receive all those events
 in an asynchroneous manner form the utility threads and run the
@@ -86,8 +75,8 @@ main loop.
 
 :)
 
-Ogg-vorbis will be used for music, using SDL_mixer.  Ship rotations
-will be performed using SDL_gfx.
+Ogg-vorbis is used for music, using SDL_mixer.  Ship rotations
+are performed using SDL_gfx rotozoom.
 
 It is very important to avoid having to link this client statically
 against GPL or LGPL libraries, because of the viral nature of those
index 6c2df42..a4bf801 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.6 2014/06/25 11:52:24 mmondor Exp $ */
+/* $Id: main.c,v 1.7 2014/06/25 12:53:13 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -64,7 +64,8 @@ static void           handle_uevent(SDL_Event *);
 static void            send_event(int, int);
 
 static SDL_Surface     *bmp_load_key(const uint8_t *, size_t);
-static int             surface_blit_angle(SDL_Surface *, int, int, int);
+static int             surface_blit_angle(SDL_Surface *, int, int, int,
+                           double);
 
 static Mix_Chunk       *sample_load(const uint8_t *, size_t);
 
@@ -93,8 +94,9 @@ static int            main_quit = 0;
 
 static int             joy_angle = 0;
 
-static SDL_Surface     *rship, *fship;
+static SDL_Surface     *rship, *fship, *ship_types[2];
 static int             shields = 1, cloaked = 0;
+static double          ship_zoom_types[2] = { 1.5, 1.0 };
 
 static Mix_Chunk       *snd_cloak, *snd_uncloak, *snd_shield, *snd_unshield,
                        *snd_torp, *snd_hit, *snd_explode;
@@ -188,6 +190,8 @@ main(int argc, char **argv)
            static_RomDD_bmp_enc_size);
        fship = bmp_load_key(static_FedCA_bmp_enc_data,
            static_FedCA_bmp_enc_size);
+       ship_types[0] = fship;
+       ship_types[1] = rship;
 
        /*
         * We're already the main thread.
@@ -625,13 +629,15 @@ frame_switch(void)
 }
 
 void
-ship_draw(int id, int x, int y, int radius, double angle, uint8_t flags)
+ship_draw(int id, int type, int x, int y, int radius, double angle,
+    uint8_t flags)
 {
        char    str[8];
 
-       (void) surface_blit_angle(rship, x, y, angle);
+       (void) surface_blit_angle(ship_types[type], x, y, angle,
+               ship_zoom_types[type]);
        if ((flags & SHIPF_CLOAK) != 0)
-               filledCircleRGBA(screen_surface, x, y, 25,
+               filledCircleRGBA(screen_surface, x, y, radius,
                    0x00, 0x00, 0x00, 0x80);
        if ((flags & SHIPF_SHIELD) != 0) {
                aacircleRGBA(screen_surface, x, y, radius,
@@ -700,7 +706,7 @@ err:
 }
 
 static int
-surface_blit_angle(SDL_Surface *s, int x, int y, int a)
+surface_blit_angle(SDL_Surface *s, int x, int y, int a, double zoom)
 {
        SDL_Surface     *t;
        SDL_Rect        d;
@@ -716,7 +722,7 @@ surface_blit_angle(SDL_Surface *s, int x, int y, int a)
        a = (a * 360 / 256) + 90;
 
        /* Interestingly, the angle has to be reversed... */
-       if ((t = rotozoomSurface(s, -a, 1.0, 1)) != NULL) {
+       if ((t = rotozoomSurface(s, -a, zoom, 1)) != NULL) {
                d = (SDL_Rect){x - (t->w / 2), y - (t->h / 2), 0, 0};
                r = SDL_BlitSurface(t, NULL, screen_surface, &d);
                SDL_FreeSurface(t);
index 3ec6c01..f94e482 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: main.h,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
+/* $Id: main.h,v 1.3 2014/06/25 12:53:13 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -23,7 +23,7 @@
 
 
 void   frame_switch(void);
-void   ship_draw(int, int, int, int, double, uint8_t);
+void   ship_draw(int, int, int, int, int, double, uint8_t);
 void   torp_draw(int, int, int);
 
 
index 61105ad..f432bba 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: packets.c,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
+/* $Id: packets.c,v 1.3 2014/06/25 12:53:13 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -165,11 +165,10 @@ spacket_ship_handler(uint16_t *ptr)
 {
        struct spacket_ship     *p = (struct spacket_ship *)ptr;
 
-       p->id = BYTEORDER_HOST16(p->id);
        p->x = BYTEORDER_HOST16(p->x);
        p->y = BYTEORDER_HOST16(p->y);
 
-       ship_draw(p->id, p->x, p->y, p->radius, p->angle, p->flags);
+       ship_draw(p->id, p->type, p->x, p->y, p->radius, p->angle, p->flags);
 
        return 0;
 }
index 836371c..1c04d4e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: packets_common.h,v 1.3 2014/06/21 17:16:32 mmondor Exp $ */
+/* $Id: packets_common.h,v 1.4 2014/06/25 12:53:13 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -79,7 +79,8 @@ struct spacket_eof {
 struct spacket_ship {
        int8_t  packet_type;
        int8_t  flags;
-       int16_t id;
+       int8_t  id;
+       int8_t  type;
        int16_t x, y;
        uint8_t radius;
        uint8_t angle;
index ed87534..6307917 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.5 2014/06/22 10:24:29 mmondor Exp $ */
+/* $Id: client.c,v 1.6 2014/06/25 12:53:14 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -101,7 +101,8 @@ client_create(int fd, struct sockaddr *saddr)
                recvq_reset(&c->recvq, c);
                (void) memcpy(&c->saddr, saddr, sizeof(struct sockaddr));
 
-               ship_init(&c->ship, SHIP_CA);
+               /* ship_init(&c->ship, SHIP_CA); */
+               ship_init(&c->ship, 1 - (random() % 2)); /* XXX */
 
                c->authenticated = c->todestroy = c->toclose = 0;
                c->writepolling = 1;
index 0cb47e8..db248a0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: packets.c,v 1.3 2014/06/21 17:16:32 mmondor Exp $ */
+/* $Id: packets.c,v 1.4 2014/06/25 12:53:14 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -219,7 +219,7 @@ k:
                                continue;
 
                        if (!c2->ship.cloak_on || c2 == c) {
-                               if (spacket_ship_send(c, (uint16_t)c2->fd,
+                               if (spacket_ship_send(c, (uint8_t)c2->fd,
                                    &c2->ship) == -1)
                                        break;
                        }
@@ -281,7 +281,7 @@ spacket_eof_send(client_t *c)
 }
 
 int
-spacket_ship_send(client_t *c, uint16_t id, ship_t *s)
+spacket_ship_send(client_t *c, uint8_t id, ship_t *s)
 {
        struct spacket_ship     p;
 
@@ -291,7 +291,8 @@ spacket_ship_send(client_t *c, uint16_t id, ship_t *s)
                p.flags |= SHIPF_SHIELD;
        if (s->cloak_on)
                p.flags |= SHIPF_CLOAK;
-       p.id = BYTEORDER_NETWORK16(id);
+       p.id = id;
+       p.type = (uint8_t)s->type;
        p.x = BYTEORDER_NETWORK16(s->x);
        p.y = BYTEORDER_NETWORK16(s->y);
        p.radius = (uint8_t)s->ship->radius;
@@ -320,7 +321,6 @@ spacket_torp_send(client_t *c, torp_t *t)
        struct spacket_torp     p;
 
        p.packet_type = SPACKET_TORP;
-       /* p.radius = c->ship.ship->torp_radius; XXX */
        p.radius = c->ship.ship->torp_radius;
        p.x = BYTEORDER_NETWORK16(t->x);
        p.y = BYTEORDER_NETWORK16(t->y);
index b45cb05..64cee78 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: packets.h,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: packets.h,v 1.2 2014/06/25 12:53:14 mmondor Exp $ */
 
 /*
  * Copyright (c) Matthew Mondor
@@ -39,7 +39,7 @@ void          packets_update(void);
 int            spacket_auth_send(client_t *);
 int            spacket_pong_send(client_t *);
 int            spacket_eof_send(client_t *);
-int            spacket_ship_send(client_t *, uint16_t, ship_t *);
+int            spacket_ship_send(client_t *, uint8_t, ship_t *);
 int            spacket_shipinfo_send(client_t *);
 int            spacket_torp_send(client_t *, torp_t *);
 
index ff8e3ba..b14524b 100644 (file)
@@ -1,7 +1,7 @@
-/* $Id: ships.c,v 1.3 2014/06/22 10:24:30 mmondor Exp $ */
+/* $Id: ships.c,v 1.4 2014/06/25 12:53:14 mmondor Exp $ */
 
 /*
- * Copyright (c) 2006, Matthew Mondor
+ * Copyright (c) 2006, 2014, Matthew Mondor
  * ALL RIGHTS RESERVED.
  */
 
@@ -21,7 +21,7 @@
 /* XXX We need to set these to decent values */
 struct shipdesc ships[SHIP_MAX] = {
        {       /* CA */
-               30.0,           /* Radius */
+               35.0,           /* Radius */
                10.0,           /* Weight */
                100.0,          /* Hull max */
                1.0,            /* Hull regen */
@@ -31,34 +31,34 @@ struct shipdesc ships[SHIP_MAX] = {
                50.0,           /* Cloak cost */
                10000.0,        /* Fuel max */
                30.0,           /* Fuel regen */
-               9.0,            /* Thrust max */
+               6.0,            /* Thrust max */
                0.20,           /* Thrust acc */
                0.30,           /* Thrust dec */
                5.0,            /* Thrust acc cost */
                5.0,            /* Thrust dec cost */
                6.0,            /* Thrust cost */
                80/*2.0*/,      /* Turn thrust */
-               0.5,            /* Turn cost */
+               1.0,            /* Turn cost */
                200.0,          /* Torp cost */
                20.0,           /* Torp damage */
                2.0,            /* Torp radius */
-               11.0,           /* Torp speed */
-               60,             /* Torp life */
+               10.0,           /* Torp speed */
+               40,             /* Torp life */
                90.0,           /* Phaser cost */
                90.0,           /* Phaser damage */
                5.0,            /* Phaser recharge */
                100.0           /* Phaser radius */
        },
        {       /* DD */
-               40.0,           /* Radius */
-               10.0,           /* Weight */
-               100.0,          /* Hull max */
-               1.0,            /* Hull regen */
-               100.0,          /* Shield max */
-               10.0,           /* Shield cost */
+               25.0,           /* Radius */
+               5.0,            /* Weight */
+               50.0,           /* Hull max */
+               2.0,            /* Hull regen */
+               50.0,           /* Shield max */
+               5.0,            /* Shield cost */
                3.0,            /* Shield regen */
-               50.0,           /* Cloak cost */
-               10000.0,        /* Fuel max */
+               25.0,           /* Cloak cost */
+               5000.0,         /* Fuel max */
                50.0,           /* Fuel regen */
                9.0,            /* Thrust max */
                0.60,           /* Thrust acc */
@@ -66,10 +66,10 @@ struct shipdesc ships[SHIP_MAX] = {
                2.0,            /* Thrust acc cost */
                2.0,            /* Thrust dec cost */
                1.0,            /* Thrust cost */
-               1.0,            /* Turn thrust */
+               100.0,          /* Turn thrust */
                0.5,            /* Turn cost */
                90.0,           /* Torp cost */
-               20.0,           /* Torp damage */
+               30.0,           /* Torp damage */
                3.0,            /* Torp radius */
                12.0,           /* Torp speed */
                60,             /* Torp life */
@@ -93,6 +93,7 @@ ship_init(ship_t *s, int type)
        d = &ships[type];
 
        s->ship = d;
+       s->type = type;
        s->hull = d->hull_max;
        s->shield = d->shield_max;
        s->fuel = d->fuel_max;
index 6b5c1ce..862b956 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ships.h,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
+/* $Id: ships.h,v 1.3 2014/06/25 12:53:14 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -41,6 +41,7 @@ typedef struct ship {
        double          fuel;
        double          thrust, i_thrust;
        double          phaser_delay;   /* phaser_cost - phaser_recharge */
+       int             type;
        int             shield_on, i_shield_on;
        int             cloak_on, i_cloak_on;
        int             torps;