From c4edeafd504a560fde78dc0c5f9280c3e012612a Mon Sep 17 00:00:00 2001 From: Paul Broadhead Date: Sat, 31 May 2014 22:05:55 +0100 Subject: [PATCH] Added support for server specified spell/buff durations. --- client_serv.h | 5 ++ draw_scene.c | 3 + multiplayer.c | 29 +++++++ multiplayer.h | 28 +++++++ named_colours.cpp | 1 + named_colours.xml | 1 + spells.c | 207 +++++++++++++++++++++++++++++++++++----------- spells.h | 2 + spells.xml | 8 -- text.c | 1 + 10 files changed, 231 insertions(+), 54 deletions(-) diff --git a/client_serv.h b/client_serv.h index 480fac8cf..0b5cc6f67 100644 --- a/client_serv.h +++ b/client_serv.h @@ -699,6 +699,9 @@ typedef enum #define DO_EMOTE 70 +/* send: 16 bit buff bit-mask (only one set bit), server responds with SEND_BUFF_DURATION */ +#define GET_BUFF_DURATION 71 + #define LOG_IN 140 #define CREATE_CHAR 141 @@ -810,6 +813,8 @@ typedef enum #define QUEST_FINISHED 94 /* sent: 5 x 32 bit integers, each active bit is an achievement the last "You see: name" player has */ #define SEND_ACHIEVEMENTS 95 +/* sent: 1 single byte duration, to get the time remaining multiply the by 10, the result is seconds */ +#define SEND_BUFF_DURATION 96 #define SEND_WEATHER 100 diff --git a/draw_scene.c b/draw_scene.c index b1ff53be2..4a4addce8 100644 --- a/draw_scene.c +++ b/draw_scene.c @@ -22,6 +22,7 @@ #include "shadows.h" #include "skeletons.h" #include "sky.h" +#include "spells.h" #include "sound.h" #include "storage.h" #include "text.h" @@ -174,6 +175,8 @@ void draw_scene() check_afk_state(); /* the timer in the hud */ update_hud_timer(); + /* check if we need to do buff duration requests */ + check_then_do_buff_duration_request(); /* until next time */ last_half_second_timer = current_time; } diff --git a/multiplayer.c b/multiplayer.c index 9e3077001..3868de198 100644 --- a/multiplayer.c +++ b/multiplayer.c @@ -104,6 +104,26 @@ Uint32 next_second_time = 0; short real_game_minute = 0; short real_game_second = 0; +/* real_game_second_valid set when we know the server seconds */ +static short real_game_second_valid = 0; +int is_real_game_second_valid(void) { return real_game_second_valid; } +void set_real_game_second_valid(void) { real_game_second_valid = 1; } + +/* get the current game time in seconds */ +Uint32 get_game_time_sec(void) +{ + return real_game_minute * 60 + real_game_second; +} + +/* get the difference between the supplied time and current game time, allowing for wrap round */ +Uint32 diff_game_time_sec(Uint32 ref_time) +{ + Uint32 curr_game_time = get_game_time_sec(); + if (ref_time > curr_game_time) + curr_game_time += 6 * 60 * 60; + return curr_game_time - ref_time; +} + /* * Date handling code: @@ -758,6 +778,7 @@ void process_message_from_server (const Uint8 *in_data, int data_length) real_game_minute= SDL_SwapLE16(*((short *)(in_data+3))); real_game_minute %= 360; real_game_second = 0; + set_real_game_second_valid(); next_second_time = cur_time+1000; if (real_game_minute < last_real_game_minute) invalidate_date(); @@ -2185,6 +2206,14 @@ void process_message_from_server (const Uint8 *in_data, int data_length) free(achievement_data); } break; + case SEND_BUFF_DURATION: + { + if (data_length <= 3) + LOG_WARNING("CAUTION: Possibly forged/invalid SEND_BUFF_DURATION packet received.\n"); + else + here_is_a_buff_duration((Uint8)in_data[3]); + break; + } default: { // Unknown packet type?? diff --git a/multiplayer.h b/multiplayer.h index 03ad0bce8..e5e23b7bf 100644 --- a/multiplayer.h +++ b/multiplayer.h @@ -36,6 +36,34 @@ extern Uint32 next_second_time; /*!< the time of the next second */ extern short real_game_minute; /*!< the real game minute */ extern short real_game_second; /*!< the real game second */ +/*! + * \brief check validity of game seconds + * + * \retval true if we have set seconds. +*/ +int is_real_game_second_valid(void); + +/*! + * \brief Set game seconds as valid. + * +*/ +void set_real_game_second_valid(void); + +/*! + * \brief Get the current game time. + * + * \retval game time in seconds. +*/ +Uint32 get_game_time_sec(void); + +/*! + * \brief Get the time difference from current game time. + * + * \param the relative time to compare + * + * \retval the time difference in seconds, wrapped appropriately +*/ +Uint32 diff_game_time_sec(Uint32 ref_time); extern time_t last_heart_beat; /*!< a timestamp that inidicates when the last message was sent to the server */ diff --git a/named_colours.cpp b/named_colours.cpp index 08dc62e46..b48607389 100644 --- a/named_colours.cpp +++ b/named_colours.cpp @@ -182,6 +182,7 @@ namespace ELGL_Colour add("minimap.otherplayer", Colour_Tuple(1.0f, 1.0f, 1.0f)); add("global.mousehighlight", Colour_Tuple(0.5f, 0.5f, 1.0f)); add("global.mouseselected", Colour_Tuple(0.4f, 0.8f, 1.0f)); + add("buff.duration.background", Colour_Tuple(0.1f, 0.3f, 1.0f, 0.7f)); } } // end namespace diff --git a/named_colours.xml b/named_colours.xml index 55d4a4041..f6c25efd2 100644 --- a/named_colours.xml +++ b/named_colours.xml @@ -14,6 +14,7 @@ + @@ -250,7 +248,6 @@ 21 1 1 - 190000 1 @@ -265,7 +262,6 @@ 15 21 1 - 130000 0 @@ -282,7 +278,6 @@ 21 2 1 - 100000 3 @@ -299,7 +294,6 @@ 3 3 4 - 120000 24 @@ -316,7 +310,6 @@ 3 3 4 - 120000 23 @@ -334,7 +327,6 @@ 3 3 4 - 160000 25 diff --git a/text.c b/text.c index ccdb3ca80..ef35bb9aa 100644 --- a/text.c +++ b/text.c @@ -530,6 +530,7 @@ int filter_or_ignore_text (char *text_to_add, int len, int size, Uint8 channel) if (from_color_char (text_to_add[0]) == c_green1 && my_strncompare(text_to_add+1,"Game Time", 9)) { real_game_second = atoi(&text_to_add[18]); + set_real_game_second_valid(); next_second_time = cur_time + 1000; new_second(); }