<commit_before>namespace QCA {
/*
Copyright (C) 1999-2004 The Botan Project. All rights reserved.

Redistribution and use in source and binary forms, for any use, with or without
modification, is permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions, and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.

IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*************************************************
* Utility Functions Source File                  *
* (C) 1999-2004 The Botan Project                *
*************************************************/

}
#include <botan/util.h>
namespace QCA {
}
#include <botan/exceptn.h>
namespace QCA {
}
#include <cmath>
namespace QCA {

namespace Botan {

#ifndef BOTAN_TOOLS_ONLY

/*************************************************
* XOR arrays together                            *
*************************************************/
void xor_buf(byte data[], const byte mask[], u32bit length)
   {
   while(length >= 8)
      {
      data[0] ^= mask[0]; data[1] ^= mask[1];
      data[2] ^= mask[2]; data[3] ^= mask[3];
      data[4] ^= mask[4]; data[5] ^= mask[5];
      data[6] ^= mask[6]; data[7] ^= mask[7];
      data += 8; mask += 8; length -= 8;
      }
   for(u32bit j = 0; j != length; j++)
      data[j] ^= mask[j];
   }

void xor_buf(byte out[], const byte in[], const byte mask[], u32bit length)
   {
   while(length >= 8)
      {
      out[0] = in[0] ^ mask[0]; out[1] = in[1] ^ mask[1];
      out[2] = in[2] ^ mask[2]; out[3] = in[3] ^ mask[3];
      out[4] = in[4] ^ mask[4]; out[5] = in[5] ^ mask[5];
      out[6] = in[6] ^ mask[6]; out[7] = in[7] ^ mask[7];
      in += 8; out += 8; mask += 8; length -= 8;
      }
   for(u32bit j = 0; j != length; j++)
      out[j] = in[j] ^ mask[j];
   }

/*************************************************
* Byte Reversal Functions                        *
*************************************************/
u16bit reverse_bytes(u16bit input)
   {
   return rotate_left(input, 8);
   }

u32bit reverse_bytes(u32bit input)
   {
   input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
   return rotate_left(input, 16);
   }

u64bit reverse_bytes(u64bit input)
   {
   input = ((input & 0xFF00FF00FF00FF00) >>  8) |
           ((input & 0x00FF00FF00FF00FF) <<  8);
   input = ((input & 0xFFFF0000FFFF0000) >> 16) |
           ((input & 0x0000FFFF0000FFFF) << 16);
   return rotate_left(input, 32);
   }

/*************************************************
* Bit Reversal Functions                         *
*************************************************/
byte reverse_bits(byte input)
   {
   input = ((input & 0xAA) >> 1) | ((input & 0x55) << 1);
   input = ((input & 0xCC) >> 2) | ((input & 0x33) << 2);
   return rotate_left(input, 4);
   }

u16bit reverse_bits(u16bit input)
   {
   input = ((input & 0xAAAA) >> 1) | ((input & 0x5555) << 1);
   input = ((input & 0xCCCC) >> 2) | ((input & 0x3333) << 2);
   input = ((input & 0xF0F0) >> 4) | ((input & 0x0F0F) << 4);
   return reverse_bytes(input);
   }

u32bit reverse_bits(u32bit input)
   {
   input = ((input & 0xAAAAAAAA) >> 1) | ((input & 0x55555555) << 1);
   input = ((input & 0xCCCCCCCC) >> 2) | ((input & 0x33333333) << 2);
   input = ((input & 0xF0F0F0F0) >> 4) | ((input & 0x0F0F0F0F) << 4);
   return reverse_bytes(input);
   }

u64bit reverse_bits(u64bit input)
   {
   input = ((input & 0xAAAAAAAAAAAAAAAA) >> 1) |
           ((input & 0x5555555555555555) << 1);
   input = ((input & 0xCCCCCCCCCCCCCCCC) >> 2) |
           ((input & 0x3333333333333333) << 2);
   input = ((input & 0xF0F0F0F0F0F0F0F0) >> 4) |
           ((input & 0x0F0F0F0F0F0F0F0F) << 4);
   return reverse_bytes(input);
   }

/*************************************************
* Return true iff arg is 2**n for some n > 0     *
*************************************************/
bool power_of_2(u64bit arg)
   {
   if(arg == 0 || arg == 1)
      return false;
   if((arg & (arg-1)) == 0)
      return true;
   return false;
   }

/*************************************************
* Combine a two time values into a single one    *
*************************************************/
u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
   {
   const u64bit NANOSECONDS_UNITS = 1000000000;
   parts *= (NANOSECONDS_UNITS / parts_hz);
   return ((seconds * NANOSECONDS_UNITS) + parts);
   }

/*************************************************
* Return the index of the highest set bit        *
*************************************************/
u32bit high_bit(u64bit n)
   {
   for(u32bit count = 64; count > 0; count--)
      if((n >> (count - 1)) & 0x01)
         return count;
   return 0;
   }

/*************************************************
* Return the index of the lowest set bit         *
*************************************************/
u32bit low_bit(u64bit n)
   {
   for(u32bit count = 0; count != 64; count++)
      if((n >> count) & 0x01)
         return (count + 1);
   return 0;
   }

/*************************************************
* Return the number of significant bytes in n    *
*************************************************/
u32bit significant_bytes(u64bit n)
   {
   for(u32bit j = 0; j != 8; j++)
      if(get_byte(j, n))
         return 8-j;
   return 0;
   }

/*************************************************
* Return the Hamming weight of n                 *
*************************************************/
u32bit hamming_weight(u64bit n)
   {
   u32bit weight = 0;
   for(u32bit j = 0; j != 64; j++)
      if((n >> j) & 0x01)
         weight++;
   return weight;
   }

#endif // BOTAN_TOOLS_ONLY

/*************************************************
* Round up n to multiple of align_to             *
*************************************************/
u32bit round_up(u32bit n, u32bit align_to)
   {
   if(n % align_to || n == 0)
      n += align_to - (n % align_to);
   return n;
   }

/*************************************************
* Round down n to multiple of align_to           *
*************************************************/
u32bit round_down(u32bit n, u32bit align_to)
   {
   return (n - (n % align_to));
   }

#ifndef BOTAN_TOOLS_ONLY

/*************************************************
* Return the work required for solving DL        *
*************************************************/
u32bit dl_work_factor(u32bit n_bits)
   {
   const u32bit MIN_ESTIMATE = 64;

   if(n_bits < 32)
      return 0;

   const double log_x = n_bits / 1.44;

   u32bit estimate = (u32bit)(2.76 * std::pow(log_x, 1.0/3.0) *
                                     std::pow(std::log(log_x), 2.0/3.0));

   return std::max(estimate, MIN_ESTIMATE);
   }

#endif // BOTAN_TOOLS_ONLY

/*************************************************
* Convert an integer into a string               *
*************************************************/
std::string to_string(u64bit n, u32bit min_len)
   {
   std::string lenstr;
   if(n)
      {
      while(n > 0)
         {
         lenstr = digit2char(n % 10) + lenstr;
         n /= 10;
         }
      }
   else
      lenstr = "0";

   while(lenstr.size() < min_len)
      lenstr = "0" + lenstr;

   return lenstr;
   }

/*************************************************
* Convert an integer into a string               *
*************************************************/
u32bit to_u32bit(const std::string& number)
   {
   u32bit n = 0;

   for(std::string::const_iterator j = number.begin(); j != number.end(); j++)
      {
      const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10;

      byte digit = char2digit(*j);

      if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5))
         throw Decoding_Error("to_u32bit: Integer overflow");
      n *= 10;
      n += digit;
      }
   return n;
   }

/*************************************************
* Check if a character represents a digit        *
*************************************************/
bool is_digit(char c)
   {
   if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
      c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
      return true;
   return false;
   }

/*************************************************
* Check if a character represents whitespace     *
*************************************************/
bool is_space(char c)
   {
   if(c == ' ' || c == '\t' || c == '\n' || c == '\r')
      return true;
   return false;
   }

/*************************************************
* Convert a character to a digit                 *
*************************************************/
byte char2digit(char c)
   {
   if(c == '0') return 0;
   if(c == '1') return 1;
   if(c == '2') return 2;
   if(c == '3') return 3;
   if(c == '4') return 4;
   if(c == '5') return 5;
   if(c == '6') return 6;
   if(c == '7') return 7;
   if(c == '8') return 8;
   if(c == '9') return 9;
   throw Invalid_Argument("char2digit: Invalid decimal char " + c);
   }

/*************************************************
* Convert a digit to a character                 *
*************************************************/
char digit2char(byte b)
   {
   if(b == 0) return '0';
   if(b == 1) return '1';
   if(b == 2) return '2';
   if(b == 3) return '3';
   if(b == 4) return '4';
   if(b == 5) return '5';
   if(b == 6) return '6';
   if(b == 7) return '7';
   if(b == 8) return '8';
   if(b == 9) return '9';
   throw Invalid_Argument("digit2char: Input is not a digit");
   }

#ifndef BOTAN_TOOLS_ONLY

/*************************************************
* Estimate the entropy of the buffer             *
*************************************************/
u32bit entropy_estimate(const byte buffer[], u32bit length)
   {
   if(length <= 4)
      return 0;

   u32bit estimate = 0;
   byte last = 0, last_delta = 0, last_delta2 = 0;

   for(u32bit j = 0; j != length; j++)
      {
      byte delta = last ^ buffer[j];
      last = buffer[j];

      byte delta2 = delta ^ last_delta;
      last_delta = delta;

      byte delta3 = delta2 ^ last_delta2;
      last_delta2 = delta2;

      byte min_delta = delta;
      if(min_delta > delta2) min_delta = delta2;
      if(min_delta > delta3) min_delta = delta3;

      estimate += hamming_weight(min_delta);
      }

   return (estimate / 2);
   }

#endif // BOTAN_TOOLS_ONLY

}
}
<commit_msg>Remove redundant include, allow QCA to build with  Intel C COmpiler.<commit_after>namespace QCA {
/*
Copyright (C) 1999-2004 The Botan Project. All rights reserved.

Redistribution and use in source and binary forms, for any use, with or without
modification, is permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions, and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.

IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*************************************************
* Utility Functions Source File                  *
* (C) 1999-2004 The Botan Project                *
*************************************************/

}
#include <botan/util.h>
namespace QCA {
}
#include <botan/exceptn.h>
namespace QCA {
}
namespace QCA {

namespace Botan {

#ifndef BOTAN_TOOLS_ONLY

/*************************************************
* XOR arrays together                            *
*************************************************/
void xor_buf(byte data[], const byte mask[], u32bit length)
   {
   while(length >= 8)
      {
      data[0] ^= mask[0]; data[1] ^= mask[1];
      data[2] ^= mask[2]; data[3] ^= mask[3];
      data[4] ^= mask[4]; data[5] ^= mask[5];
      data[6] ^= mask[6]; data[7] ^= mask[7];
      data += 8; mask += 8; length -= 8;
      }
   for(u32bit j = 0; j != length; j++)
      data[j] ^= mask[j];
   }

void xor_buf(byte out[], const byte in[], const byte mask[], u32bit length)
   {
   while(length >= 8)
      {
      out[0] = in[0] ^ mask[0]; out[1] = in[1] ^ mask[1];
      out[2] = in[2] ^ mask[2]; out[3] = in[3] ^ mask[3];
      out[4] = in[4] ^ mask[4]; out[5] = in[5] ^ mask[5];
      out[6] = in[6] ^ mask[6]; out[7] = in[7] ^ mask[7];
      in += 8; out += 8; mask += 8; length -= 8;
      }
   for(u32bit j = 0; j != length; j++)
      out[j] = in[j] ^ mask[j];
   }

/*************************************************
* Byte Reversal Functions                        *
*************************************************/
u16bit reverse_bytes(u16bit input)
   {
   return rotate_left(input, 8);
   }

u32bit reverse_bytes(u32bit input)
   {
   input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
   return rotate_left(input, 16);
   }

u64bit reverse_bytes(u64bit input)
   {
   input = ((input & 0xFF00FF00FF00FF00) >>  8) |
           ((input & 0x00FF00FF00FF00FF) <<  8);
   input = ((input & 0xFFFF0000FFFF0000) >> 16) |
           ((input & 0x0000FFFF0000FFFF) << 16);
   return rotate_left(input, 32);
   }

/*************************************************
* Bit Reversal Functions                         *
*************************************************/
byte reverse_bits(byte input)
   {
   input = ((input & 0xAA) >> 1) | ((input & 0x55) << 1);
   input = ((input & 0xCC) >> 2) | ((input & 0x33) << 2);
   return rotate_left(input, 4);
   }

u16bit reverse_bits(u16bit input)
   {
   input = ((input & 0xAAAA) >> 1) | ((input & 0x5555) << 1);
   input = ((input & 0xCCCC) >> 2) | ((input & 0x3333) << 2);
   input = ((input & 0xF0F0) >> 4) | ((input & 0x0F0F) << 4);
   return reverse_bytes(input);
   }

u32bit reverse_bits(u32bit input)
   {
   input = ((input & 0xAAAAAAAA) >> 1) | ((input & 0x55555555) << 1);
   input = ((input & 0xCCCCCCCC) >> 2) | ((input & 0x33333333) << 2);
   input = ((input & 0xF0F0F0F0) >> 4) | ((input & 0x0F0F0F0F) << 4);
   return reverse_bytes(input);
   }

u64bit reverse_bits(u64bit input)
   {
   input = ((input & 0xAAAAAAAAAAAAAAAA) >> 1) |
           ((input & 0x5555555555555555) << 1);
   input = ((input & 0xCCCCCCCCCCCCCCCC) >> 2) |
           ((input & 0x3333333333333333) << 2);
   input = ((input & 0xF0F0F0F0F0F0F0F0) >> 4) |
           ((input & 0x0F0F0F0F0F0F0F0F) << 4);
   return reverse_bytes(input);
   }

/*************************************************
* Return true iff arg is 2**n for some n > 0     *
*************************************************/
bool power_of_2(u64bit arg)
   {
   if(arg == 0 || arg == 1)
      return false;
   if((arg & (arg-1)) == 0)
      return true;
   return false;
   }

/*************************************************
* Combine a two time values into a single one    *
*************************************************/
u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
   {
   const u64bit NANOSECONDS_UNITS = 1000000000;
   parts *= (NANOSECONDS_UNITS / parts_hz);
   return ((seconds * NANOSECONDS_UNITS) + parts);
   }

/*************************************************
* Return the index of the highest set bit        *
*************************************************/
u32bit high_bit(u64bit n)
   {
   for(u32bit count = 64; count > 0; count--)
      if((n >> (count - 1)) & 0x01)
         return count;
   return 0;
   }

/*************************************************
* Return the index of the lowest set bit         *
*************************************************/
u32bit low_bit(u64bit n)
   {
   for(u32bit count = 0; count != 64; count++)
      if((n >> count) & 0x01)
         return (count + 1);
   return 0;
   }

/*************************************************
* Return the number of significant bytes in n    *
*************************************************/
u32bit significant_bytes(u64bit n)
   {
   for(u32bit j = 0; j != 8; j++)
      if(get_byte(j, n))
         return 8-j;
   return 0;
   }

/*************************************************
* Return the Hamming weight of n                 *
*************************************************/
u32bit hamming_weight(u64bit n)
   {
   u32bit weight = 0;
   for(u32bit j = 0; j != 64; j++)
      if((n >> j) & 0x01)
         weight++;
   return weight;
   }

#endif // BOTAN_TOOLS_ONLY

/*************************************************
* Round up n to multiple of align_to             *
*************************************************/
u32bit round_up(u32bit n, u32bit align_to)
   {
   if(n % align_to || n == 0)
      n += align_to - (n % align_to);
   return n;
   }

/*************************************************
* Round down n to multiple of align_to           *
*************************************************/
u32bit round_down(u32bit n, u32bit align_to)
   {
   return (n - (n % align_to));
   }

#ifndef BOTAN_TOOLS_ONLY

/*************************************************
* Return the work required for solving DL        *
*************************************************/
u32bit dl_work_factor(u32bit n_bits)
   {
   const u32bit MIN_ESTIMATE = 64;

   if(n_bits < 32)
      return 0;

   const double log_x = n_bits / 1.44;

   u32bit estimate = (u32bit)(2.76 * std::pow(log_x, 1.0/3.0) *
                                     std::pow(std::log(log_x), 2.0/3.0));

   return std::max(estimate, MIN_ESTIMATE);
   }

#endif // BOTAN_TOOLS_ONLY

/*************************************************
* Convert an integer into a string               *
*************************************************/
std::string to_string(u64bit n, u32bit min_len)
   {
   std::string lenstr;
   if(n)
      {
      while(n > 0)
         {
         lenstr = digit2char(n % 10) + lenstr;
         n /= 10;
         }
      }
   else
      lenstr = "0";

   while(lenstr.size() < min_len)
      lenstr = "0" + lenstr;

   return lenstr;
   }

/*************************************************
* Convert an integer into a string               *
*************************************************/
u32bit to_u32bit(const std::string& number)
   {
   u32bit n = 0;

   for(std::string::const_iterator j = number.begin(); j != number.end(); j++)
      {
      const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10;

      byte digit = char2digit(*j);

      if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5))
         throw Decoding_Error("to_u32bit: Integer overflow");
      n *= 10;
      n += digit;
      }
   return n;
   }

/*************************************************
* Check if a character represents a digit        *
*************************************************/
bool is_digit(char c)
   {
   if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
      c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
      return true;
   return false;
   }

/*************************************************
* Check if a character represents whitespace     *
*************************************************/
bool is_space(char c)
   {
   if(c == ' ' || c == '\t' || c == '\n' || c == '\r')
      return true;
   return false;
   }

/*************************************************
* Convert a character to a digit                 *
*************************************************/
byte char2digit(char c)
   {
   if(c == '0') return 0;
   if(c == '1') return 1;
   if(c == '2') return 2;
   if(c == '3') return 3;
   if(c == '4') return 4;
   if(c == '5') return 5;
   if(c == '6') return 6;
   if(c == '7') return 7;
   if(c == '8') return 8;
   if(c == '9') return 9;
   throw Invalid_Argument("char2digit: Invalid decimal char " + c);
   }

/*************************************************
* Convert a digit to a character                 *
*************************************************/
char digit2char(byte b)
   {
   if(b == 0) return '0';
   if(b == 1) return '1';
   if(b == 2) return '2';
   if(b == 3) return '3';
   if(b == 4) return '4';
   if(b == 5) return '5';
   if(b == 6) return '6';
   if(b == 7) return '7';
   if(b == 8) return '8';
   if(b == 9) return '9';
   throw Invalid_Argument("digit2char: Input is not a digit");
   }

#ifndef BOTAN_TOOLS_ONLY

/*************************************************
* Estimate the entropy of the buffer             *
*************************************************/
u32bit entropy_estimate(const byte buffer[], u32bit length)
   {
   if(length <= 4)
      return 0;

   u32bit estimate = 0;
   byte last = 0, last_delta = 0, last_delta2 = 0;

   for(u32bit j = 0; j != length; j++)
      {
      byte delta = last ^ buffer[j];
      last = buffer[j];

      byte delta2 = delta ^ last_delta;
      last_delta = delta;

      byte delta3 = delta2 ^ last_delta2;
      last_delta2 = delta2;

      byte min_delta = delta;
      if(min_delta > delta2) min_delta = delta2;
      if(min_delta > delta3) min_delta = delta3;

      estimate += hamming_weight(min_delta);
      }

   return (estimate / 2);
   }

#endif // BOTAN_TOOLS_ONLY

}
}
<|endoftext|>


<commit_before>/* bzflag
 * Copyright (c) 1993 - 2004 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4: 4786)
#endif

#include <iostream>

#include "BZAdminClient.h"
#include "StateDatabase.h"
#include "TextUtils.h"
#include "version.h"

BZAdminClient::BZAdminClient(std::string callsign, std::string host,
			     int port, BZAdminUI* bzInterface)
  : myTeam(ObserverTeam), sLink(Address(host), port), valid(false),
    ui(bzInterface) {

  if (sLink.getState() != ServerLink::Okay) {
    std::cerr<<"Could not connect to "<<host<<':'<<port<<'.'<<std::endl;
    return;
  }
  sLink.sendEnter(TankPlayer, myTeam, callsign.c_str(), "");
  if (sLink.getState() != ServerLink::Okay) {
    std::cerr<<"Rejected."<<std::endl;
    return;
  }
  valid = true;

  // set a default message mask
  showMessageType(MsgAddPlayer);
  showMessageType(MsgRemovePlayer);
  showMessageType(MsgSuperKill);
  showMessageType(MsgMessage);
  showMessageType(MsgSetVar);

  // initialise the colormap
  colorMap[NoTeam] = Yellow;
  colorMap[RogueTeam] = Yellow;
  colorMap[RedTeam] = Red;
  colorMap[GreenTeam] = Green;
  colorMap[BlueTeam] = Blue;
  colorMap[PurpleTeam] = Purple;
  colorMap[ObserverTeam] = LightBlue;
}

PlayerId BZAdminClient::getMyId() {
  return sLink.getId();
}

BZAdminClient::ServerCode
BZAdminClient::getServerString(std::string& str, ColorCode& colorCode) {
  uint16_t code, len;
  char inbuf[MaxPacketLen];
  int e;
  std::string dstName, srcName;
  std::string returnString = "";
  int i;
  colorCode = Default;

  /* read until we have a package that we want, or until there are no more
     packages for 100 ms */
  while ((e = sLink.read(code, len, inbuf, 100)) == 1) {
    // check if we're interested in this message type
    if (!messageMask[code])
      continue;

    void* vbuf = inbuf;
    PlayerId p;
    PlayerIdMap::const_iterator it;
    std::string victimName, killerName;

    switch (code) {

    case MsgSetVar:
      // code stolen from playing.cxx
      uint16_t numVars;
      uint8_t nameLen, valueLen;

      char name[MaxPacketLen];
      char value[MaxPacketLen];

      vbuf = nboUnpackUShort(vbuf, numVars);
      for (i = 0; i < numVars; i++) {
	vbuf = nboUnpackUByte(vbuf, nameLen);
	vbuf = nboUnpackString(vbuf, name, nameLen);
	name[nameLen] = '\0';

	vbuf = nboUnpackUByte(vbuf, valueLen);
	vbuf = nboUnpackString(vbuf, value, valueLen);
	value[valueLen] = '\0';

	BZDB.set(name, value);
	BZDB.setPersistent(name, false);
	BZDB.setPermission(name, StateDatabase::Locked);
      }
      str = returnString;
      return GotMessage;

    case MsgAddPlayer:

      vbuf = nboUnpackUByte(vbuf, p);

      uint16_t team, type, wins, losses, tks;
      char callsign[CallSignLen];
      char email[EmailLen];
      vbuf = nboUnpackUShort(vbuf, type);
      vbuf = nboUnpackUShort(vbuf, team);
      vbuf = nboUnpackUShort(vbuf, wins);
      vbuf = nboUnpackUShort(vbuf, losses);
      vbuf = nboUnpackUShort(vbuf, tks);
      vbuf = nboUnpackString(vbuf, callsign, CallSignLen);
      vbuf = nboUnpackString(vbuf, email, EmailLen);
      players[p].name.resize(0);
      players[p].name.append(callsign);
      players[p].team = TeamColor(team);
      if (ui != NULL)
	ui->addedPlayer(p);
      returnString = returnString + "*** '" + callsign + "' joined the game.";
      str = returnString;
      return GotMessage;

    case MsgRemovePlayer:
      vbuf = nboUnpackUByte(vbuf, p);
      returnString = returnString + "*** '" + players[p].name +
	"' left the game.";
      if (ui != NULL)
	ui->removingPlayer(p);
      players.erase(p);
      str = returnString;
      return GotMessage;

    case MsgKilled:
      PlayerId victim, killer;
      int16_t shotId, reason;
      vbuf = nboUnpackUByte(vbuf, victim);
      vbuf = nboUnpackUByte(vbuf, killer);
      vbuf = nboUnpackShort(vbuf, reason);
      vbuf = nboUnpackShort(vbuf, shotId);

      // find the player names and build a kill message string
      it = players.find(victim);
      victimName = (it != players.end() ? it->second.name : "<unknown>");
      it = players.find(killer);
      killerName = (it != players.end() ? it->second.name : "<unknown>");
      returnString = "*** ";
      returnString += victimName + ": ";
      if (killer == victim) {
	returnString += "blew myself up";
      }
      else {
	returnString += "destroyed by ";
	returnString += killerName;
      }
      str = returnString;
      return GotMessage;

    case MsgSuperKill:
      str = returnString;
      return Superkilled;

    case MsgMessage:

      // unpack the message header
      PlayerId src;
      PlayerId dst;
      PlayerId me = sLink.getId();
      vbuf = nboUnpackUByte(vbuf, src);
      vbuf = nboUnpackUByte(vbuf, dst);
      returnString = std::string((char*)vbuf);

      // parse playerlist
      if (src == ServerPlayer && returnString[0] == '[') {
	char* ipHere;
	p = PlayerId(std::strtol(returnString.c_str() + 1, &ipHere, 10));
	if (ipHere[0] == ']') {
	  std::vector<std::string> tokens;
	  tokens = string_util::tokenize(ipHere + 1, " ");
	  if (*tokens.rbegin() == "udp" || *tokens.rbegin() == "udp+")
	    tokens.pop_back();
	  if (tokens.size() >= 2) {
	    std::string callsign = *(++tokens.rbegin());
	    if (*callsign.rbegin() == ':') {
	      players[p].ip = *tokens.rbegin();
	    }
	  }
	}
      }

      // is the message for me?
      TeamColor dstTeam = (dst >= 244 && dst <= 250 ?
			   TeamColor(250 - dst) : NoTeam);
      if (dst == AllPlayers || src == me || dst == me || dstTeam == myTeam) {
	if (returnString == "CLIENTQUERY") {
	  sendMessage(std::string("bzadmin ") + getAppVersion(), src);
	  if (ui != NULL)
	    ui->outputMessage("    [Sent versioninfo per request]", Default);
	}
	else {
	  returnString = formatMessage((char*)vbuf, src, dst, dstTeam, me);
	  str = returnString;
	  PlayerIdMap::const_iterator iter = players.find(src);
	  colorCode = (iter == players.end() ?
		       colorMap[NoTeam] : colorMap[iter->second.team]);
	  return GotMessage;
	}
      }
    }
  }

  if (sLink.getState() != ServerLink::Okay) {
    str = returnString;
    return CommError;
  }

  str = returnString;
  return NoMessage;
}

BZAdminClient::ServerCode
BZAdminClient::getServerString(std::string& str) {
  ColorCode cc;
  return getServerString(str, cc);
}

PlayerIdMap& BZAdminClient::getPlayers() {
  return players;
}

bool BZAdminClient::isValid() const {
  return valid;
}

void BZAdminClient::runLoop() {
  std::string str;
  ColorCode color;
  ServerCode what(NoMessage);
  while (true) {
    while ((what = getServerString(str, color)) == GotMessage) {
      if (ui != NULL)
	ui->outputMessage(str, color);
    }
    if (what == Superkilled || what == CommError)
      break;
    if (ui != NULL && ui->checkCommand(str)) {
      if (str == "/quit")
	break;
      sendMessage(str, ui->getTarget());
    }
  }

  // why did we leave the loop?
  switch (what) {
  case Superkilled:
    if (ui != NULL)
      ui->outputMessage("--- ERROR: Server forced disconnect", Red);
    break;
  case CommError:
    if (ui != NULL)
      ui->outputMessage("--- ERROR: Connection to server lost", Red);
    break;
  default:
    waitForServer();
  }
}

void BZAdminClient::sendMessage(const std::string& msg,
				PlayerId target) {
  // /set is a local command, don't send it, just list the BZDB variables
  if (msg == "/set") {
    if (ui != NULL)
      BZDB.iterate(listSetVars, this);
    return;
  }

  char buffer[MessageLen];
  char buffer2[1 + MessageLen];
  void* buf = buffer2;

  buf = nboPackUByte(buf, target);
  memset(buffer, 0, MessageLen);
  strncpy(buffer, msg.c_str(), MessageLen - 1);
  nboPackString(buffer2 + 1, buffer, MessageLen);
  sLink.send(MsgMessage, sizeof(buffer2), buffer2);
}

std::string BZAdminClient::formatMessage(const std::string& msg, PlayerId src,
				    PlayerId dst, TeamColor dstTeam,
				    PlayerId me) {
  std::string formatted = "    ";

  // get sender and receiver
  const std::string srcName = (src == ServerPlayer ? "SERVER" :
			       (players.count(src) ? players[src].name :
				"(UNKNOWN)"));
  const std::string dstName = (players.count(dst) ? players[dst].name :
			       "(UNKNOWN)");

  // direct message to or from me
  if (dst == me || players.count(dst)) {
    if (!(src == me && dst == me)) {
      formatted += "[";
      if (src == me) {
	formatted += "->";
	formatted += dstName;
      }
      else {
	formatted += srcName;
	formatted += "->";
      }
      formatted += "] ";
    }
    formatted += msg;
  }

  // public or team message
  else {
    if (dstTeam != NoTeam)
      formatted += "[Team] ";
    formatted += srcName;
    formatted += ": ";
    formatted += msg;
  }

  return formatted;
}

void BZAdminClient::setUI(BZAdminUI* bzInterface) {
  ui = bzInterface;
}

void BZAdminClient::waitForServer() {
  // we need to know that the server has processed all our messages
  // send a private message to ourself and wait for it to come back
  // this assumes that the order of messages isn't changed along the way
  PlayerId me = sLink.getId();
  if (sLink.getState() == ServerLink::Okay) {
    sendMessage("bzadminping", me);
    std::string expected = formatMessage("bzadminping", me, me, NoTeam, me);
    std::string str;
    do {
      getServerString(str);
    } while (str != expected);
  }
}

void BZAdminClient::ignoreMessageType(uint16_t type) {
  messageMask[type] = false;
}

void BZAdminClient::showMessageType(uint16_t type) {
  messageMask[type] = true;
}

void BZAdminClient::listSetVars(const std::string& name, void* thisObject) {
  char message[MessageLen];
  if (BZDB.getPermission(name) == StateDatabase::Locked) {
    sprintf(message, "/set %s %f", name.c_str(), BZDB.eval(name));
    ((BZAdminClient*)thisObject)->ui->outputMessage(message, Default);
  }
}

// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
<commit_msg>no std::strtol on win32<commit_after>/* bzflag
 * Copyright (c) 1993 - 2004 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4: 4786)
#endif

#include <iostream>

#include "BZAdminClient.h"
#include "StateDatabase.h"
#include "TextUtils.h"
#include "version.h"

BZAdminClient::BZAdminClient(std::string callsign, std::string host,
			     int port, BZAdminUI* bzInterface)
  : myTeam(ObserverTeam), sLink(Address(host), port), valid(false),
    ui(bzInterface) {

  if (sLink.getState() != ServerLink::Okay) {
    std::cerr<<"Could not connect to "<<host<<':'<<port<<'.'<<std::endl;
    return;
  }
  sLink.sendEnter(TankPlayer, myTeam, callsign.c_str(), "");
  if (sLink.getState() != ServerLink::Okay) {
    std::cerr<<"Rejected."<<std::endl;
    return;
  }
  valid = true;

  // set a default message mask
  showMessageType(MsgAddPlayer);
  showMessageType(MsgRemovePlayer);
  showMessageType(MsgSuperKill);
  showMessageType(MsgMessage);
  showMessageType(MsgSetVar);

  // initialise the colormap
  colorMap[NoTeam] = Yellow;
  colorMap[RogueTeam] = Yellow;
  colorMap[RedTeam] = Red;
  colorMap[GreenTeam] = Green;
  colorMap[BlueTeam] = Blue;
  colorMap[PurpleTeam] = Purple;
  colorMap[ObserverTeam] = LightBlue;
}

PlayerId BZAdminClient::getMyId() {
  return sLink.getId();
}

BZAdminClient::ServerCode
BZAdminClient::getServerString(std::string& str, ColorCode& colorCode) {
  uint16_t code, len;
  char inbuf[MaxPacketLen];
  int e;
  std::string dstName, srcName;
  std::string returnString = "";
  int i;
  colorCode = Default;

  /* read until we have a package that we want, or until there are no more
     packages for 100 ms */
  while ((e = sLink.read(code, len, inbuf, 100)) == 1) {
    // check if we're interested in this message type
    if (!messageMask[code])
      continue;

    void* vbuf = inbuf;
    PlayerId p;
    PlayerIdMap::const_iterator it;
    std::string victimName, killerName;

    switch (code) {

    case MsgSetVar:
      // code stolen from playing.cxx
      uint16_t numVars;
      uint8_t nameLen, valueLen;

      char name[MaxPacketLen];
      char value[MaxPacketLen];

      vbuf = nboUnpackUShort(vbuf, numVars);
      for (i = 0; i < numVars; i++) {
	vbuf = nboUnpackUByte(vbuf, nameLen);
	vbuf = nboUnpackString(vbuf, name, nameLen);
	name[nameLen] = '\0';

	vbuf = nboUnpackUByte(vbuf, valueLen);
	vbuf = nboUnpackString(vbuf, value, valueLen);
	value[valueLen] = '\0';

	BZDB.set(name, value);
	BZDB.setPersistent(name, false);
	BZDB.setPermission(name, StateDatabase::Locked);
      }
      str = returnString;
      return GotMessage;

    case MsgAddPlayer:

      vbuf = nboUnpackUByte(vbuf, p);

      uint16_t team, type, wins, losses, tks;
      char callsign[CallSignLen];
      char email[EmailLen];
      vbuf = nboUnpackUShort(vbuf, type);
      vbuf = nboUnpackUShort(vbuf, team);
      vbuf = nboUnpackUShort(vbuf, wins);
      vbuf = nboUnpackUShort(vbuf, losses);
      vbuf = nboUnpackUShort(vbuf, tks);
      vbuf = nboUnpackString(vbuf, callsign, CallSignLen);
      vbuf = nboUnpackString(vbuf, email, EmailLen);
      players[p].name.resize(0);
      players[p].name.append(callsign);
      players[p].team = TeamColor(team);
      if (ui != NULL)
	ui->addedPlayer(p);
      returnString = returnString + "*** '" + callsign + "' joined the game.";
      str = returnString;
      return GotMessage;

    case MsgRemovePlayer:
      vbuf = nboUnpackUByte(vbuf, p);
      returnString = returnString + "*** '" + players[p].name +
	"' left the game.";
      if (ui != NULL)
	ui->removingPlayer(p);
      players.erase(p);
      str = returnString;
      return GotMessage;

    case MsgKilled:
      PlayerId victim, killer;
      int16_t shotId, reason;
      vbuf = nboUnpackUByte(vbuf, victim);
      vbuf = nboUnpackUByte(vbuf, killer);
      vbuf = nboUnpackShort(vbuf, reason);
      vbuf = nboUnpackShort(vbuf, shotId);

      // find the player names and build a kill message string
      it = players.find(victim);
      victimName = (it != players.end() ? it->second.name : "<unknown>");
      it = players.find(killer);
      killerName = (it != players.end() ? it->second.name : "<unknown>");
      returnString = "*** ";
      returnString += victimName + ": ";
      if (killer == victim) {
	returnString += "blew myself up";
      }
      else {
	returnString += "destroyed by ";
	returnString += killerName;
      }
      str = returnString;
      return GotMessage;

    case MsgSuperKill:
      str = returnString;
      return Superkilled;

    case MsgMessage:

      // unpack the message header
      PlayerId src;
      PlayerId dst;
      PlayerId me = sLink.getId();
      vbuf = nboUnpackUByte(vbuf, src);
      vbuf = nboUnpackUByte(vbuf, dst);
      returnString = std::string((char*)vbuf);

      // parse playerlist
      if (src == ServerPlayer && returnString[0] == '[') {
	char* ipHere;
#ifdef _WIN32
	p = PlayerId(atol(returnString.c_str() + 1);
#else
	p = PlayerId(std::strtol(returnString.c_str() + 1, &ipHere, 10));
#endif
	if (ipHere[0] == ']') {
	  std::vector<std::string> tokens;
	  tokens = string_util::tokenize(ipHere + 1, " ");
	  if (*tokens.rbegin() == "udp" || *tokens.rbegin() == "udp+")
	    tokens.pop_back();
	  if (tokens.size() >= 2) {
	    std::string callsign = *(++tokens.rbegin());
	    if (*callsign.rbegin() == ':') {
	      players[p].ip = *tokens.rbegin();
	    }
	  }
	}
      }

      // is the message for me?
      TeamColor dstTeam = (dst >= 244 && dst <= 250 ?
			   TeamColor(250 - dst) : NoTeam);
      if (dst == AllPlayers || src == me || dst == me || dstTeam == myTeam) {
	if (returnString == "CLIENTQUERY") {
	  sendMessage(std::string("bzadmin ") + getAppVersion(), src);
	  if (ui != NULL)
	    ui->outputMessage("    [Sent versioninfo per request]", Default);
	}
	else {
	  returnString = formatMessage((char*)vbuf, src, dst, dstTeam, me);
	  str = returnString;
	  PlayerIdMap::const_iterator iter = players.find(src);
	  colorCode = (iter == players.end() ?
		       colorMap[NoTeam] : colorMap[iter->second.team]);
	  return GotMessage;
	}
      }
    }
  }

  if (sLink.getState() != ServerLink::Okay) {
    str = returnString;
    return CommError;
  }

  str = returnString;
  return NoMessage;
}

BZAdminClient::ServerCode
BZAdminClient::getServerString(std::string& str) {
  ColorCode cc;
  return getServerString(str, cc);
}

PlayerIdMap& BZAdminClient::getPlayers() {
  return players;
}

bool BZAdminClient::isValid() const {
  return valid;
}

void BZAdminClient::runLoop() {
  std::string str;
  ColorCode color;
  ServerCode what(NoMessage);
  while (true) {
    while ((what = getServerString(str, color)) == GotMessage) {
      if (ui != NULL)
	ui->outputMessage(str, color);
    }
    if (what == Superkilled || what == CommError)
      break;
    if (ui != NULL && ui->checkCommand(str)) {
      if (str == "/quit")
	break;
      sendMessage(str, ui->getTarget());
    }
  }

  // why did we leave the loop?
  switch (what) {
  case Superkilled:
    if (ui != NULL)
      ui->outputMessage("--- ERROR: Server forced disconnect", Red);
    break;
  case CommError:
    if (ui != NULL)
      ui->outputMessage("--- ERROR: Connection to server lost", Red);
    break;
  default:
    waitForServer();
  }
}

void BZAdminClient::sendMessage(const std::string& msg,
				PlayerId target) {
  // /set is a local command, don't send it, just list the BZDB variables
  if (msg == "/set") {
    if (ui != NULL)
      BZDB.iterate(listSetVars, this);
    return;
  }

  char buffer[MessageLen];
  char buffer2[1 + MessageLen];
  void* buf = buffer2;

  buf = nboPackUByte(buf, target);
  memset(buffer, 0, MessageLen);
  strncpy(buffer, msg.c_str(), MessageLen - 1);
  nboPackString(buffer2 + 1, buffer, MessageLen);
  sLink.send(MsgMessage, sizeof(buffer2), buffer2);
}

std::string BZAdminClient::formatMessage(const std::string& msg, PlayerId src,
				    PlayerId dst, TeamColor dstTeam,
				    PlayerId me) {
  std::string formatted = "    ";

  // get sender and receiver
  const std::string srcName = (src == ServerPlayer ? "SERVER" :
			       (players.count(src) ? players[src].name :
				"(UNKNOWN)"));
  const std::string dstName = (players.count(dst) ? players[dst].name :
			       "(UNKNOWN)");

  // direct message to or from me
  if (dst == me || players.count(dst)) {
    if (!(src == me && dst == me)) {
      formatted += "[";
      if (src == me) {
	formatted += "->";
	formatted += dstName;
      }
      else {
	formatted += srcName;
	formatted += "->";
      }
      formatted += "] ";
    }
    formatted += msg;
  }

  // public or team message
  else {
    if (dstTeam != NoTeam)
      formatted += "[Team] ";
    formatted += srcName;
    formatted += ": ";
    formatted += msg;
  }

  return formatted;
}

void BZAdminClient::setUI(BZAdminUI* bzInterface) {
  ui = bzInterface;
}

void BZAdminClient::waitForServer() {
  // we need to know that the server has processed all our messages
  // send a private message to ourself and wait for it to come back
  // this assumes that the order of messages isn't changed along the way
  PlayerId me = sLink.getId();
  if (sLink.getState() == ServerLink::Okay) {
    sendMessage("bzadminping", me);
    std::string expected = formatMessage("bzadminping", me, me, NoTeam, me);
    std::string str;
    do {
      getServerString(str);
    } while (str != expected);
  }
}

void BZAdminClient::ignoreMessageType(uint16_t type) {
  messageMask[type] = false;
}

void BZAdminClient::showMessageType(uint16_t type) {
  messageMask[type] = true;
}

void BZAdminClient::listSetVars(const std::string& name, void* thisObject) {
  char message[MessageLen];
  if (BZDB.getPermission(name) == StateDatabase::Locked) {
    sprintf(message, "/set %s %f", name.c_str(), BZDB.eval(name));
    ((BZAdminClient*)thisObject)->ui->outputMessage(message, Default);
  }
}

// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
<|endoftext|>


<commit_before>#include "stdafx.h"

#include "ETypes.h"
#include "ViewInvisible.h"
#include <ATF/global.hpp>
#include <ATF/_player_fixpositon_zocl.hpp>

namespace GameServer
{
    namespace Fixes
    {
        using namespace ATF;

        void CViewInvisible::load()
        {
            auto& core = CATFCore::get_instance();
            core.set_hook(&CPlayer::SendMsg_FixPosition, &CViewInvisible::CPlayer_SendMsg_FixPosition);
            core.set_hook(&CPlayer::SendMsg_OtherShapePart, &CViewInvisible::CPlayer__SendMsg_OtherShapePart);
            core.set_hook(&CPlayer::SendMsg_OtherShapeAll, &CViewInvisible::CPlayer__SendMsg_OtherShapeAll);
        }

        void CViewInvisible::unload()
        {
            auto& core = CATFCore::get_instance();
            core.unset_hook(&CPlayer::SendMsg_FixPosition);
            core.unset_hook(&CPlayer::SendMsg_OtherShapePart);
            core.unset_hook(&CPlayer::SendMsg_OtherShapeAll);
        }

        void CViewInvisible::loop()
        {
        }

        ModuleVersion_t CViewInvisible::get_version()
        {
            return usVersion;
        }

        ModuleName_t CViewInvisible::get_name()
        {
            static const ModuleName_t name = "fix_viewinvisible";
            return name;
        }

        void CViewInvisible::configure(
            const rapidjson::Value & nodeConfig)
        {
            UNREFERENCED_PARAMETER(nodeConfig);
        }

        bool check_conditions(ATF::CPlayer *pPlayer, ATF::CPlayer *pDst)
        {
            bool bPassed = false;
            do
            {
                if (pPlayer->m_bObserver && !pDst->m_byUserDgr)
                    break;

                if (pPlayer->m_EP.GetEff_State((int)ATF::_EFF_STATE::Stealth) ||
                    pPlayer->m_EP.GetEff_State((int)ATF::_EFF_STATE::Invisible) ||
                    pPlayer->m_EP.GetEff_State((int)ATF::_EFF_STATE::Invincible) ||
                    pPlayer->m_EP.GetEff_Plus((int)ATF::_EFF_PLUS::Transparency))
                {
                    if (!pDst->m_EP.GetEff_Plus((int)ATF::_EFF_PLUS::Detect))
                    {
                        break;
                    }
                }

                bPassed = true;
            } while (false);

            return bPassed;
        }

        void WINAPIV CViewInvisible::CPlayer_SendMsg_FixPosition(
            ATF::CPlayer* pPlayer,
            int dwClientIndex,
            ATF::info::CPlayerSendMsg_FixPosition752_ptr next)
        {
            UNREFERENCED_PARAMETER(next);

            CPlayer* pDstPlayer = &global::g_Player[dwClientIndex];
            if (!check_conditions(pPlayer, pDstPlayer))
                return;

            char pbyType[2]{ 4, 9 };
            ATF::_player_fixpositon_zocl szMsg;

            szMsg.wIndex = pPlayer->m_ObjID.m_wIndex;
            szMsg.dwSerial = pPlayer->m_dwObjSerial;
            szMsg.wEquipVer = pPlayer->GetVisualVer();
            ATF::global::FloatToShort(pPlayer->m_fCurPos, szMsg.zCur, 3);
            szMsg.byRaceCode = pPlayer->m_Param.GetRaceSexCode();
            szMsg.dwStateFlag = pPlayer->GetStateFlag();
            szMsg.wLastEffectCode = pPlayer->m_wLastContEffect;
            szMsg.byColor = pPlayer->m_byGuildBattleColorInx;
            ATF::global::g_NetProcess[(uint8_t)e_type_line::client]->LoadSendMsg(dwClientIndex, pbyType, (char *)&szMsg, sizeof(szMsg));
        }

        void WINAPIV CViewInvisible::CPlayer__SendMsg_OtherShapePart(
            ATF::CPlayer * pPlayer,
            ATF::CPlayer * pDst,
            ATF::info::CPlayerSendMsg_OtherShapePart914_ptr next)
        {
            UNREFERENCED_PARAMETER(next);
            if (!check_conditions(pPlayer, pDst))
                return;

            if (!pPlayer->m_bLive)
            {
                pPlayer->SendMsg_OtherShapeError(pDst, 0);
                return;
            }

            char pbyType[2]{ 3, 0x20 };
            auto const test = sizeof(ATF::CGameObject);

            ATF::global::g_NetProcess[(uint8_t)e_type_line::client]->LoadSendMsg(pDst->m_ObjID.m_wIndex, pbyType, (char *)&pPlayer->m_bufSpapePart, pPlayer->m_bufSpapePart.size());
        }

        void WINAPIV CViewInvisible::CPlayer__SendMsg_OtherShapeAll(
            ATF::CPlayer * pPlayer,
            ATF::CPlayer * pDst,
            ATF::info::CPlayerSendMsg_OtherShapeAll910_ptr next)
        {
            UNREFERENCED_PARAMETER(next);
            if (!check_conditions(pPlayer, pDst))
                return;

            if (!pPlayer->m_bLive)
            {
                pPlayer->SendMsg_OtherShapeError(pDst, 0);
                return;
            }

            char pbyType[2]{ 3, 0x1f };
            auto const test = sizeof(ATF::CGameObject);

            ATF::global::g_NetProcess[(uint8_t)e_type_line::client]->LoadSendMsg(pDst->m_ObjID.m_wIndex, pbyType, (char *)&pPlayer->m_bufShapeAll, pPlayer->m_bufShapeAll.size());
        }
    }
}<commit_msg>Removed excess check<commit_after>#include "stdafx.h"

#include "ETypes.h"
#include "ViewInvisible.h"
#include <ATF/global.hpp>
#include <ATF/_player_fixpositon_zocl.hpp>

namespace GameServer
{
    namespace Fixes
    {
        using namespace ATF;

        void CViewInvisible::load()
        {
            auto& core = CATFCore::get_instance();
            core.set_hook(&CPlayer::SendMsg_FixPosition, &CViewInvisible::CPlayer_SendMsg_FixPosition);
            core.set_hook(&CPlayer::SendMsg_OtherShapePart, &CViewInvisible::CPlayer__SendMsg_OtherShapePart);
            core.set_hook(&CPlayer::SendMsg_OtherShapeAll, &CViewInvisible::CPlayer__SendMsg_OtherShapeAll);
        }

        void CViewInvisible::unload()
        {
            auto& core = CATFCore::get_instance();
            core.unset_hook(&CPlayer::SendMsg_FixPosition);
            core.unset_hook(&CPlayer::SendMsg_OtherShapePart);
            core.unset_hook(&CPlayer::SendMsg_OtherShapeAll);
        }

        void CViewInvisible::loop()
        {
        }

        ModuleVersion_t CViewInvisible::get_version()
        {
            return usVersion;
        }

        ModuleName_t CViewInvisible::get_name()
        {
            static const ModuleName_t name = "fix_viewinvisible";
            return name;
        }

        void CViewInvisible::configure(
            const rapidjson::Value & nodeConfig)
        {
            UNREFERENCED_PARAMETER(nodeConfig);
        }

        bool check_conditions(ATF::CPlayer *pPlayer, ATF::CPlayer *pDst)
        {
            bool bPassed = false;
            do
            {
                if (pPlayer->m_bObserver && !pDst->m_byUserDgr)
                    break;

                if (pPlayer->m_EP.GetEff_State((int)ATF::_EFF_STATE::Stealth))
                {
                    if (!pDst->m_EP.GetEff_Plus((int)ATF::_EFF_PLUS::Detect))
                    {
                        break;
                    }
                }

                bPassed = true;
            } while (false);

            return bPassed;
        }

        void WINAPIV CViewInvisible::CPlayer_SendMsg_FixPosition(
            ATF::CPlayer* pPlayer,
            int dwClientIndex,
            ATF::info::CPlayerSendMsg_FixPosition752_ptr next)
        {
            UNREFERENCED_PARAMETER(next);

            CPlayer* pDstPlayer = &global::g_Player[dwClientIndex];
            if (!check_conditions(pPlayer, pDstPlayer))
                return;

            char pbyType[2]{ 4, 9 };
            ATF::_player_fixpositon_zocl szMsg;

            szMsg.wIndex = pPlayer->m_ObjID.m_wIndex;
            szMsg.dwSerial = pPlayer->m_dwObjSerial;
            szMsg.wEquipVer = pPlayer->GetVisualVer();
            ATF::global::FloatToShort(pPlayer->m_fCurPos, szMsg.zCur, 3);
            szMsg.byRaceCode = pPlayer->m_Param.GetRaceSexCode();
            szMsg.dwStateFlag = pPlayer->GetStateFlag();
            szMsg.wLastEffectCode = pPlayer->m_wLastContEffect;
            szMsg.byColor = pPlayer->m_byGuildBattleColorInx;
            ATF::global::g_NetProcess[(uint8_t)e_type_line::client]->LoadSendMsg(dwClientIndex, pbyType, (char *)&szMsg, sizeof(szMsg));
        }

        void WINAPIV CViewInvisible::CPlayer__SendMsg_OtherShapePart(
            ATF::CPlayer * pPlayer,
            ATF::CPlayer * pDst,
            ATF::info::CPlayerSendMsg_OtherShapePart914_ptr next)
        {
            UNREFERENCED_PARAMETER(next);
            if (!check_conditions(pPlayer, pDst))
                return;

            if (!pPlayer->m_bLive)
            {
                pPlayer->SendMsg_OtherShapeError(pDst, 0);
                return;
            }

            char pbyType[2]{ 3, 0x20 };
            auto const test = sizeof(ATF::CGameObject);

            ATF::global::g_NetProcess[(uint8_t)e_type_line::client]->LoadSendMsg(pDst->m_ObjID.m_wIndex, pbyType, (char *)&pPlayer->m_bufSpapePart, pPlayer->m_bufSpapePart.size());
        }

        void WINAPIV CViewInvisible::CPlayer__SendMsg_OtherShapeAll(
            ATF::CPlayer * pPlayer,
            ATF::CPlayer * pDst,
            ATF::info::CPlayerSendMsg_OtherShapeAll910_ptr next)
        {
            UNREFERENCED_PARAMETER(next);
            if (!check_conditions(pPlayer, pDst))
                return;

            if (!pPlayer->m_bLive)
            {
                pPlayer->SendMsg_OtherShapeError(pDst, 0);
                return;
            }

            char pbyType[2]{ 3, 0x1f };
            auto const test = sizeof(ATF::CGameObject);

            ATF::global::g_NetProcess[(uint8_t)e_type_line::client]->LoadSendMsg(pDst->m_ObjID.m_wIndex, pbyType, (char *)&pPlayer->m_bufShapeAll, pPlayer->m_bufShapeAll.size());
        }
    }
}<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: dataview.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: fs $ $Date: 2002-05-22 14:02:12 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef DBAUI_DATAVIEW_HXX
#include "dataview.hxx"
#endif
#ifndef _TOOLBOX_HXX //autogen
#include <vcl/toolbox.hxx>
#endif
#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
#include <toolkit/unohlp.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _SFXAPP_HXX //autogen wg. SFX_APP
#include <sfx2/app.hxx>
#endif
#ifndef _SFXIMGMGR_HXX
#include <sfx2/imgmgr.hxx>
#endif
#ifndef _SV_FIXED_HXX
#include <vcl/fixed.hxx>
#endif
#ifndef DBAUI_ICONTROLLER_HXX
#include "IController.hxx"
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef _SFX_HRC
#include <sfx2/sfx.hrc>
#endif
#ifndef _SVTOOLS_IMGDEF_HXX
#include <svtools/imgdef.hxx>
#endif

//.........................................................................
namespace dbaui
{
//.........................................................................
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::util;
    using namespace ::com::sun::star::lang;

    //=====================================================================
    //= ColorChanger
    //=====================================================================
    class ColorChanger
    {
    protected:
        OutputDevice*   m_pDev;

    public:
        ColorChanger( OutputDevice* _pDev, const Color& _rNewLineColor, const Color& _rNewFillColor )
            :m_pDev( _pDev )
        {
            m_pDev->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
            m_pDev->SetLineColor( _rNewLineColor );
            m_pDev->SetFillColor( _rNewFillColor );
        }

        ~ColorChanger()
        {
            m_pDev->Pop();
        }
    };

    DBG_NAME(ODataView)
    // -------------------------------------------------------------------------
    ODataView::ODataView(   Window* pParent,
                            IController* _pController,
                            const Reference< XMultiServiceFactory >& _rFactory,
                            WinBits nStyle)
        :Window(pParent,nStyle)
        ,m_xServiceFactory(_rFactory)
        ,m_pSeparator( NULL )
        ,m_pController( _pController )
    {
        DBG_CTOR(ODataView,NULL);
        OSL_ENSURE(m_pController,"Controller must be not NULL!");
    }

    // -------------------------------------------------------------------------
    void ODataView::Construct()
    {
    }

    // -------------------------------------------------------------------------
    ODataView::~ODataView()
    {
        setToolBox(NULL);

        enableSeparator( sal_False );

        DBG_DTOR(ODataView,NULL);
    }

    // -------------------------------------------------------------------------
    void ODataView::enableSeparator( const sal_Bool _bEnable )
    {
        if ( _bEnable == isSeparatorEnabled() )
            // nothing to do
            return;

        if ( _bEnable )
        {
            m_pSeparator = new FixedLine( this );
            m_pSeparator->Show( );
        }
        else
        {
            delete m_pSeparator;
            m_pSeparator = NULL;
        }
        Resize();
    }
    // -------------------------------------------------------------------------
    void ODataView::setToolBox(ToolBox* pTB)
    {
        if (pTB == getToolBox())
            return;

        if (getToolBox())
        {
            notifySystemWindow(this,getToolBox(),::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
            delete getToolBox();
        }

        OToolBoxHelper::setToolBox(pTB);
        if ( getToolBox() )
        {
            getToolBox()->SetParent(this);
            notifySystemWindow(this,getToolBox(),::comphelper::mem_fun(&TaskPaneList::AddWindow));
            getToolBox()->Show();
        }

        // rearrange the grid and the TB
        Resize();
    }
    // -------------------------------------------------------------------------
    void ODataView::resizeDocumentView( Rectangle& _rPlayground )
    {
    }

    // -------------------------------------------------------------------------
    void ODataView::Paint( const Rectangle& _rRect )
    {
        //.................................................................
        // draw the background
        {
            ColorChanger aColors( this, COL_TRANSPARENT, GetSettings().GetStyleSettings().GetFaceColor() );
            DrawRect( _rRect );
        }

        // let the base class do anything it needs
        Window::Paint( _rRect );
    }

    // -------------------------------------------------------------------------
    void ODataView::resizeAll( const Rectangle& _rPlayground )
    {
        Rectangle aPlayground( _rPlayground );

        // position thew separator
        if ( m_pSeparator )
        {
            Size aSeparatorSize = Size( aPlayground.GetWidth(), 2 );

            m_pSeparator->SetPosSizePixel( aPlayground.TopLeft(), aSeparatorSize );

            aPlayground.Top() += aSeparatorSize.Height() + 1;
        }

        // position the tool box
        if ( getToolBox() )
        {
            ::Point aToolboxPos( aPlayground.TopLeft() );
            aToolboxPos.Y() += 2;
            getToolBox()->SetPosPixel( aToolboxPos );

            ::Size aToolboxSize( aPlayground.GetSize().Width(), getToolBox()->GetSizePixel().Height() );
            getToolBox()->SetSizePixel( aToolboxSize );

            aPlayground.Top() += aToolboxSize.Height() + 4;
        }

        // position the controls of the document's view
        resizeDocumentView( aPlayground );
    }

    // -------------------------------------------------------------------------
    void ODataView::Resize()
    {
        Window::Resize();
        Size aSize = GetSizePixel();
        if(aSize.Width() > 0 && aSize.Height() > 0)
            resizeAll( Rectangle( Point( 0, 0), GetSizePixel() ) );
    }
    // -----------------------------------------------------------------------------
    long ODataView::PreNotify( NotifyEvent& rNEvt )
    {
        BOOL bHandled = FALSE;
        switch (rNEvt.GetType())
        {
            case EVENT_KEYINPUT:
            {
                const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
                const KeyCode& aKeyCode = pKeyEvent->GetKeyCode();
                ::rtl::OUString sCommand;

                if ( aKeyCode.IsMod1() )
                {
                    switch ( pKeyEvent->GetKeyCode().GetCode() )
                    {
                        case KEY_S:
                        {
                            sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Save"));
                            bHandled = TRUE;
                            break;
                        }
                        case KEY_Z:
                        {
                            sCommand =  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Undo"));
                            bHandled = TRUE;
                            break;
                        }
                    }
                }
                if ( bHandled )
                {
                    URL aCommand;
                    aCommand.Complete = sCommand;
                    m_pController->executeChecked( aCommand );
                }
            }
            break;
        }
        return bHandled ? 1L : Window::PreNotify(rNEvt);
    }
    // -----------------------------------------------------------------------------
    void ODataView::StateChanged( StateChangedType nType )
    {
        Window::StateChanged( nType );

        if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
        {
            // Check if we need to get new images for normal/high contrast mode
            checkImageList();
            m_pController->notifyHiContrastChanged();
        }
        else if ( nType == STATE_CHANGE_TEXT )
        {
            // The physical toolbar changed its outlook and shows another logical toolbar!
            // We have to set the correct high contrast mode on the new tbx manager.
            //  checkImageList();
            //  notifyHiContrastChanged(isHiContrast());
        }
    }
    // -----------------------------------------------------------------------------
    void ODataView::DataChanged( const DataChangedEvent& rDCEvt )
    {
        Window::DataChanged( rDCEvt );

        if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS )   ||
            ( rDCEvt.GetType() == DATACHANGED_DISPLAY   ))  &&
            ( rDCEvt.GetFlags() & SETTINGS_STYLE        ))
        {
            // Check if we need to get new images for normal/high contrast mode
            checkImageList();
            m_pController->notifyHiContrastChanged();
        }
    }
    // -----------------------------------------------------------------------------
    sal_Int16 ODataView::getImageListId(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
    {
        sal_Int16 nN = RID_DEFAULTIMAGELIST_SC;
        sal_Int16 nH = RID_DEFAULTIMAGELIST_SCH;
        if ( _eBitmapSet == SFX_SYMBOLS_LARGE )
        {
            nN = RID_DEFAULTIMAGELIST_LC;
            nH = RID_DEFAULTIMAGELIST_LCH;
        }

        return _bHiContast ? nH : nN;
    }
//.........................................................................
}
// namespace dbaui
//.........................................................................
<commit_msg>#95146# now acquire and release controller when set<commit_after>/*************************************************************************
 *
 *  $RCSfile: dataview.cxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: oj $ $Date: 2002-07-25 07:08:55 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef DBAUI_DATAVIEW_HXX
#include "dataview.hxx"
#endif
#ifndef _TOOLBOX_HXX //autogen
#include <vcl/toolbox.hxx>
#endif
#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
#include <toolkit/unohlp.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _SFXAPP_HXX //autogen wg. SFX_APP
#include <sfx2/app.hxx>
#endif
#ifndef _SFXIMGMGR_HXX
#include <sfx2/imgmgr.hxx>
#endif
#ifndef _SV_FIXED_HXX
#include <vcl/fixed.hxx>
#endif
#ifndef DBAUI_ICONTROLLER_HXX
#include "IController.hxx"
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef _SFX_HRC
#include <sfx2/sfx.hrc>
#endif
#ifndef _SVTOOLS_IMGDEF_HXX
#include <svtools/imgdef.hxx>
#endif

//.........................................................................
namespace dbaui
{
//.........................................................................
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::util;
    using namespace ::com::sun::star::lang;

    //=====================================================================
    //= ColorChanger
    //=====================================================================
    class ColorChanger
    {
    protected:
        OutputDevice*   m_pDev;

    public:
        ColorChanger( OutputDevice* _pDev, const Color& _rNewLineColor, const Color& _rNewFillColor )
            :m_pDev( _pDev )
        {
            m_pDev->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
            m_pDev->SetLineColor( _rNewLineColor );
            m_pDev->SetFillColor( _rNewFillColor );
        }

        ~ColorChanger()
        {
            m_pDev->Pop();
        }
    };

    DBG_NAME(ODataView)
    // -------------------------------------------------------------------------
    ODataView::ODataView(   Window* pParent,
                            IController* _pController,
                            const Reference< XMultiServiceFactory >& _rFactory,
                            WinBits nStyle)
        :Window(pParent,nStyle)
        ,m_xServiceFactory(_rFactory)
        ,m_pSeparator( NULL )
        ,m_pController( _pController )
    {
        DBG_CTOR(ODataView,NULL);
        OSL_ENSURE(m_pController,"Controller must be not NULL!");
        m_pController->acquire();
    }

    // -------------------------------------------------------------------------
    void ODataView::Construct()
    {
    }

    // -------------------------------------------------------------------------
    ODataView::~ODataView()
    {
        setToolBox(NULL);

        enableSeparator( sal_False );
        m_pController->release();

        DBG_DTOR(ODataView,NULL);
    }

    // -------------------------------------------------------------------------
    void ODataView::enableSeparator( const sal_Bool _bEnable )
    {
        if ( _bEnable == isSeparatorEnabled() )
            // nothing to do
            return;

        if ( _bEnable )
        {
            m_pSeparator = new FixedLine( this );
            m_pSeparator->Show( );
        }
        else
        {
            delete m_pSeparator;
            m_pSeparator = NULL;
        }
        Resize();
    }
    // -------------------------------------------------------------------------
    void ODataView::setToolBox(ToolBox* pTB)
    {
        if (pTB == getToolBox())
            return;

        if (getToolBox())
        {
            notifySystemWindow(this,getToolBox(),::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
            delete getToolBox();
        }

        OToolBoxHelper::setToolBox(pTB);
        if ( getToolBox() )
        {
            getToolBox()->SetParent(this);
            notifySystemWindow(this,getToolBox(),::comphelper::mem_fun(&TaskPaneList::AddWindow));
            getToolBox()->Show();
        }

        // rearrange the grid and the TB
        Resize();
    }
    // -------------------------------------------------------------------------
    void ODataView::resizeDocumentView( Rectangle& _rPlayground )
    {
    }

    // -------------------------------------------------------------------------
    void ODataView::Paint( const Rectangle& _rRect )
    {
        //.................................................................
        // draw the background
        {
            ColorChanger aColors( this, COL_TRANSPARENT, GetSettings().GetStyleSettings().GetFaceColor() );
            DrawRect( _rRect );
        }

        // let the base class do anything it needs
        Window::Paint( _rRect );
    }

    // -------------------------------------------------------------------------
    void ODataView::resizeAll( const Rectangle& _rPlayground )
    {
        Rectangle aPlayground( _rPlayground );

        // position thew separator
        if ( m_pSeparator )
        {
            Size aSeparatorSize = Size( aPlayground.GetWidth(), 2 );

            m_pSeparator->SetPosSizePixel( aPlayground.TopLeft(), aSeparatorSize );

            aPlayground.Top() += aSeparatorSize.Height() + 1;
        }

        // position the tool box
        if ( getToolBox() )
        {
            ::Point aToolboxPos( aPlayground.TopLeft() );
            aToolboxPos.Y() += 2;
            getToolBox()->SetPosPixel( aToolboxPos );

            ::Size aToolboxSize( aPlayground.GetSize().Width(), getToolBox()->GetSizePixel().Height() );
            getToolBox()->SetSizePixel( aToolboxSize );

            aPlayground.Top() += aToolboxSize.Height() + 4;
        }

        // position the controls of the document's view
        resizeDocumentView( aPlayground );
    }

    // -------------------------------------------------------------------------
    void ODataView::Resize()
    {
        Window::Resize();
        resizeAll( Rectangle( Point( 0, 0), GetSizePixel() ) );
    }
    // -----------------------------------------------------------------------------
    long ODataView::PreNotify( NotifyEvent& rNEvt )
    {
        BOOL bHandled = FALSE;
        switch (rNEvt.GetType())
        {
            case EVENT_KEYINPUT:
            {
                const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
                const KeyCode& aKeyCode = pKeyEvent->GetKeyCode();
                ::rtl::OUString sCommand;

                if ( aKeyCode.IsMod1() )
                {
                    switch ( pKeyEvent->GetKeyCode().GetCode() )
                    {
                        case KEY_S:
                        {
                            sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Save"));
                            bHandled = TRUE;
                            break;
                        }
                        case KEY_Z:
                        {
                            sCommand =  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Undo"));
                            bHandled = TRUE;
                            break;
                        }
                    }
                }
                if ( bHandled )
                {
                    URL aCommand;
                    aCommand.Complete = sCommand;
                    m_pController->executeChecked( aCommand );
                }
            }
            break;
        }
        return bHandled ? 1L : Window::PreNotify(rNEvt);
    }
    // -----------------------------------------------------------------------------
    void ODataView::StateChanged( StateChangedType nType )
    {
        Window::StateChanged( nType );

        if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
        {
            // Check if we need to get new images for normal/high contrast mode
            checkImageList();
            m_pController->notifyHiContrastChanged();
        }
        else if ( nType == STATE_CHANGE_TEXT )
        {
            // The physical toolbar changed its outlook and shows another logical toolbar!
            // We have to set the correct high contrast mode on the new tbx manager.
            //  checkImageList();
            //  notifyHiContrastChanged(isHiContrast());
        }
    }
    // -----------------------------------------------------------------------------
    void ODataView::DataChanged( const DataChangedEvent& rDCEvt )
    {
        Window::DataChanged( rDCEvt );

        if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS )   ||
            ( rDCEvt.GetType() == DATACHANGED_DISPLAY   ))  &&
            ( rDCEvt.GetFlags() & SETTINGS_STYLE        ))
        {
            // Check if we need to get new images for normal/high contrast mode
            checkImageList();
            m_pController->notifyHiContrastChanged();
        }
    }
    // -----------------------------------------------------------------------------
    sal_Int16 ODataView::getImageListId(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
    {
        sal_Int16 nN = RID_DEFAULTIMAGELIST_SC;
        sal_Int16 nH = RID_DEFAULTIMAGELIST_SCH;
        if ( _eBitmapSet == SFX_SYMBOLS_LARGE )
        {
            nN = RID_DEFAULTIMAGELIST_LC;
            nH = RID_DEFAULTIMAGELIST_LCH;
        }

        return _bHiContast ? nH : nN;
    }
//.........................................................................
}
// namespace dbaui
//.........................................................................
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unoDirectSql.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2007-07-24 12:10:39 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"

#ifndef DBAUI_UNODIRECTSQL_HXX
#include "unoDirectSql.hxx"
#endif
#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONNECTION_XCONNECTION_HPP_
#include <com/sun/star/connection/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
#include <com/sun/star/container/XNamed.hpp>
#endif
#ifndef _DBACCESS_UI_DIRECTSQL_HXX_
#include "directsql.hxx"
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _DBAUI_DATASOURCECONNECTOR_HXX_
#include "datasourceconnector.hxx"
#endif

extern "C" void SAL_CALL createRegistryInfo_ODirectSQLDialog()
{
    static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::ODirectSQLDialog > aAutoRegistration;
}

//.........................................................................
namespace dbaui
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace ::com::sun::star::container;
    using namespace ::com::sun::star::sdbcx;
    using namespace ::com::sun::star::sdbc;
    using namespace ::com::sun::star::sdb;

    //=====================================================================
    //= ODirectSQLDialog
    //=====================================================================
DBG_NAME(ODirectSQLDialog)
//---------------------------------------------------------------------
    ODirectSQLDialog::ODirectSQLDialog(const Reference< XMultiServiceFactory >& _rxORB)
        :ODirectSQLDialog_BASE( _rxORB )
    {
        DBG_CTOR(ODirectSQLDialog,NULL);

    }

    //---------------------------------------------------------------------
    ODirectSQLDialog::~ODirectSQLDialog()
    {

        DBG_DTOR(ODirectSQLDialog,NULL);
    }

    //---------------------------------------------------------------------
    IMPLEMENT_IMPLEMENTATION_ID( ODirectSQLDialog )

    //---------------------------------------------------------------------
    IMPLEMENT_SERVICE_INFO1_STATIC( ODirectSQLDialog, "com.sun.star.comp.sdb.DirectSQLDialog", SERVICE_SDB_DIRECTSQLDIALOG )

    //---------------------------------------------------------------------
    IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ODirectSQLDialog )

    //---------------------------------------------------------------------
    Dialog* ODirectSQLDialog::createDialog(Window* _pParent)
    {
        // obtain all the objects needed for the dialog
        Reference< XConnection > xConnection = m_xActiveConnection;
        if ( !xConnection.is() )
        {
            try
            {
                // the connection the row set is working with
                ODatasourceConnector aDSConnector(m_xORB,_pParent);
                xConnection = aDSConnector.connect(m_sInitialSelection);
            }
            catch( const Exception& )
            {
                OSL_ENSURE( sal_False, "ODirectSQLDialog::createDialog: caught an exception!" );
            }
        }
        if ( !xConnection.is() )
            // can't create the dialog if I have improper settings
            return NULL;

        return new DirectSQLDialog( _pParent, xConnection);
    }
    //---------------------------------------------------------------------
    void ODirectSQLDialog::implInitialize(const Any& _rValue)
    {
        PropertyValue aProperty;
        if (_rValue >>= aProperty)
        {
            if (0 == aProperty.Name.compareToAscii("InitialSelection"))
            {
                OSL_VERIFY( aProperty.Value >>= m_sInitialSelection );
                return;
            }
            else if (0 == aProperty.Name.compareToAscii("ActiveConnection"))
            {
                m_xActiveConnection.set( aProperty.Value, UNO_QUERY );
                OSL_ENSURE( m_xActiveConnection.is(), "ODirectSQLDialog::implInitialize: invalid connection!" );
                return;
            }
        }
        ODirectSQLDialog_BASE::implInitialize(_rValue);
    }
//.........................................................................
}   // namespace dbaui
//.........................................................................

<commit_msg>INTEGRATION: CWS changefileheader (1.7.146); FILE MERGED 2008/03/31 13:28:10 rt 1.7.146.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: unoDirectSql.cxx,v $
 * $Revision: 1.8 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"

#ifndef DBAUI_UNODIRECTSQL_HXX
#include "unoDirectSql.hxx"
#endif
#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONNECTION_XCONNECTION_HPP_
#include <com/sun/star/connection/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
#include <com/sun/star/container/XNamed.hpp>
#endif
#ifndef _DBACCESS_UI_DIRECTSQL_HXX_
#include "directsql.hxx"
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _DBAUI_DATASOURCECONNECTOR_HXX_
#include "datasourceconnector.hxx"
#endif

extern "C" void SAL_CALL createRegistryInfo_ODirectSQLDialog()
{
    static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::ODirectSQLDialog > aAutoRegistration;
}

//.........................................................................
namespace dbaui
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace ::com::sun::star::container;
    using namespace ::com::sun::star::sdbcx;
    using namespace ::com::sun::star::sdbc;
    using namespace ::com::sun::star::sdb;

    //=====================================================================
    //= ODirectSQLDialog
    //=====================================================================
DBG_NAME(ODirectSQLDialog)
//---------------------------------------------------------------------
    ODirectSQLDialog::ODirectSQLDialog(const Reference< XMultiServiceFactory >& _rxORB)
        :ODirectSQLDialog_BASE( _rxORB )
    {
        DBG_CTOR(ODirectSQLDialog,NULL);

    }

    //---------------------------------------------------------------------
    ODirectSQLDialog::~ODirectSQLDialog()
    {

        DBG_DTOR(ODirectSQLDialog,NULL);
    }

    //---------------------------------------------------------------------
    IMPLEMENT_IMPLEMENTATION_ID( ODirectSQLDialog )

    //---------------------------------------------------------------------
    IMPLEMENT_SERVICE_INFO1_STATIC( ODirectSQLDialog, "com.sun.star.comp.sdb.DirectSQLDialog", SERVICE_SDB_DIRECTSQLDIALOG )

    //---------------------------------------------------------------------
    IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ODirectSQLDialog )

    //---------------------------------------------------------------------
    Dialog* ODirectSQLDialog::createDialog(Window* _pParent)
    {
        // obtain all the objects needed for the dialog
        Reference< XConnection > xConnection = m_xActiveConnection;
        if ( !xConnection.is() )
        {
            try
            {
                // the connection the row set is working with
                ODatasourceConnector aDSConnector(m_xORB,_pParent);
                xConnection = aDSConnector.connect(m_sInitialSelection);
            }
            catch( const Exception& )
            {
                OSL_ENSURE( sal_False, "ODirectSQLDialog::createDialog: caught an exception!" );
            }
        }
        if ( !xConnection.is() )
            // can't create the dialog if I have improper settings
            return NULL;

        return new DirectSQLDialog( _pParent, xConnection);
    }
    //---------------------------------------------------------------------
    void ODirectSQLDialog::implInitialize(const Any& _rValue)
    {
        PropertyValue aProperty;
        if (_rValue >>= aProperty)
        {
            if (0 == aProperty.Name.compareToAscii("InitialSelection"))
            {
                OSL_VERIFY( aProperty.Value >>= m_sInitialSelection );
                return;
            }
            else if (0 == aProperty.Name.compareToAscii("ActiveConnection"))
            {
                m_xActiveConnection.set( aProperty.Value, UNO_QUERY );
                OSL_ENSURE( m_xActiveConnection.is(), "ODirectSQLDialog::implInitialize: invalid connection!" );
                return;
            }
        }
        ODirectSQLDialog_BASE::implInitialize(_rValue);
    }
//.........................................................................
}   // namespace dbaui
//.........................................................................

<|endoftext|>


<commit_before>// RUN: %clang -target x86_64-unknown-nacl -ccc-echo %s -emit-llvm-only -c 2>&1 | FileCheck %s -check-prefix=ECHO
// RUN: %clang -target x86_64-unknown-nacl %s -emit-llvm -S -c -o - | FileCheck %s
// RUN: %clang -target x86_64-unknown-nacl %s -emit-llvm -S -c -pthread -o - | FileCheck %s -check-prefix=THREADS

// ECHO: {{.*}} -cc1 {{.*}}x86_64-nacl-defines.c

// Check platform defines

// CHECK: __LITTLE_ENDIAN__defined
#ifdef __LITTLE_ENDIAN__
void __LITTLE_ENDIAN__defined() {}
#endif

// CHECK: __native_client__defined
#ifdef __native_client__
void __native_client__defined() {}
#endif

// CHECK: __x86_64__defined
#ifdef __x86_64__
void __x86_64__defined() {}
#endif

// CHECK: unixdefined
#ifdef unix
void unixdefined() {}
#endif

// CHECK: __ELF__defined
#ifdef __ELF__
void __ELF__defined() {}
#endif

// CHECK: _GNU_SOURCEdefined
#ifdef _GNU_SOURCE
void _GNU_SOURCEdefined() {}
#endif

// THREADS: _REENTRANTdefined
// CHECK: _REENTRANTundefined
#ifdef _REENTRANT
void _REENTRANTdefined() {}
#else
void _REENTRANTundefined() {}
#endif
<commit_msg>clang/test/Driver/x86_64-nacl-defines.cpp: Specify filename generated.<commit_after>// RUN: %clang -target x86_64-unknown-nacl -ccc-echo %s -emit-llvm-only -c -o %t.o 2>&1 | FileCheck %s -check-prefix=ECHO
// RUN: %clang -target x86_64-unknown-nacl %s -emit-llvm -S -c -o - | FileCheck %s
// RUN: %clang -target x86_64-unknown-nacl %s -emit-llvm -S -c -pthread -o - | FileCheck %s -check-prefix=THREADS

// ECHO: {{.*}} -cc1 {{.*}}x86_64-nacl-defines.c

// Check platform defines

// CHECK: __LITTLE_ENDIAN__defined
#ifdef __LITTLE_ENDIAN__
void __LITTLE_ENDIAN__defined() {}
#endif

// CHECK: __native_client__defined
#ifdef __native_client__
void __native_client__defined() {}
#endif

// CHECK: __x86_64__defined
#ifdef __x86_64__
void __x86_64__defined() {}
#endif

// CHECK: unixdefined
#ifdef unix
void unixdefined() {}
#endif

// CHECK: __ELF__defined
#ifdef __ELF__
void __ELF__defined() {}
#endif

// CHECK: _GNU_SOURCEdefined
#ifdef _GNU_SOURCE
void _GNU_SOURCEdefined() {}
#endif

// THREADS: _REENTRANTdefined
// CHECK: _REENTRANTundefined
#ifdef _REENTRANT
void _REENTRANTdefined() {}
#else
void _REENTRANTundefined() {}
#endif
<|endoftext|>