Skip to content

Commit

Permalink
Merge branch 'master' into itemprop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhobean authored Oct 24, 2023
2 parents cf6c6aa + bc50050 commit ab1404c
Show file tree
Hide file tree
Showing 86 changed files with 2,438 additions and 1,434 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverity-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ jobs:
TOKEN: ${{ secrets.COVERITY_TOKEN }}
#echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
run: |
wget -nv https://scan.coverity.com/download/cxx/linux64 --post-data "token=${TOKEN}&project=SphereServer/Source-X" -O cov-analysis-linux64.tar.gz
wget -nv https://scan.coverity.com/download/cxx/linux64 --post-data "token=${TOKEN}&project=Sphereserver/Source-X" -O cov-analysis-linux64.tar.gz
mkdir cov-analysis-linux64
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
export PATH=`pwd`/cov-analysis-linux64/bin:$PATH
- name: CMake
run: |
mkdir -p build
cmake -G "Makefiles" -DCMAKE_BUILD_TYPE="Nightly" -DCMAKE_TOOLCHAIN_FILE=src/cmake/toolchains/Linux-GNU-x86_64.cmake -S ./ -B ./build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Nightly" -DCMAKE_TOOLCHAIN_FILE=src/cmake/toolchains/Linux-GNU-x86_64.cmake -S ./ -B ./build
- name: Compilation (cov-build)
run: |
Expand Down
17 changes: 16 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,10 @@ Additionally, the problem of zig-zag issue following in the South direction has
- Fixed: Possible random errors caused by reading some internal data before it was initialized during server startup (CCrypto::client_keys, holding SphereCrypt data, and ThreadHolder, holding threads data).
- Fixed: CSString instances becoming invalid after calling the Clear method.

18-10-2023, xwerswoodx
- [Port from 0.56d, Coruja] 56b TILLER DCLick auto pilot to X. (Request: #778)
- Fixed: Possible fix for Osi Client spell flood. (Issue: #787, #776)

19-10-2023, Julian
- Fixed: Missing SkillUpdate function, seems I never commited it.
- Modified: @SkillMenu trigger to be able to open dialogs also, and added a few local variables.
Expand All @@ -3408,5 +3412,16 @@ Additionally, the problem of zig-zag issue following in the South direction has
- Modified: @SkillMakeItem trigger to enable/disable notification message when bouncing the crafted item.
LOCAL.Notify (rw) = 1/0. Using 0 will not show any "You put your..." message, 1 will show it. Default = 1.

19-10-2023, Jhobean
21-10-2023, xwerswoodx
- [Port from 0.56d, Coruja] Implemented the new chat system from 56d. (Feature Request: #785)
https://github.com/Sphereserver/Source/commit/ead8e666810d63a58f133de26ebe69095d12c52c
https://github.com/Sphereserver/Source/commit/2ccf98dc3c4ae7e910ea87cd3d4b5f90e499fe92
https://github.com/Sphereserver/Source/commit/26039d2ef9a121d52b561ce02cdae6d1e4624ccc
https://github.com/Sphereserver/Source/commit/f26b39b9b40fba76660c36d57baa8387d3613272
https://github.com/Sphereserver/Source/commit/722606c54f17e3c9d8e6095fffcaa3b528c4783a
- Fixed: Activated disabled DEFNAME variable for Skills (Issue: #1138)
- Fixed: NPCs that is not walking in multis shown wrong region name after server reboot.

24-10-2023, Jhobean
- Added: Item properties functionnality:HITAREAPHYSICAL,HITAREAFIRE,HITAREACOLD,HITAREAPOISON,HITAREAENERGY,HITFIREBALL,HITHARM,HITLIGHTNING,HITMAGICARROW,REFLECTPHYSICALDAM

2 changes: 1 addition & 1 deletion lib/CMakeSources.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
INCLUDE_DIRECTORIES (
lib/mariadb/
lib/flat_containers/
lib/object_ptr/
lib/parallel_hashmap/
lib/regex/
lib/variant_w_base/
)

# LibEv files
Expand Down
90 changes: 90 additions & 0 deletions lib/object_ptr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# `jss::object_ptr<T>`

[![Build Status](https://travis-ci.com/anthonywilliams/object_ptr.svg?branch=master)](https://travis-ci.com/anthonywilliams/object_ptr)

This is an implementation of a class similar
to [`std::experimental::observer_ptr`](https://en.cppreference.com/w/cpp/experimental/observer_ptr)
from the [Library Fundamentals TS v2](http://wg21.link/n4562), but with various improvements
suggested in WG21 email discussions of the feature.

## Differences to `std::experimental::observer_ptr`

The most obvious change is the name: `observer_ptr` is a bad name, because it conjures up the idea
of the Observer pattern, but it doesn't really "observe" anything. I believe `object_ptr` is better:
it is a pointer to an object, so doesn't have any array-related functionality such as pointer
arithmetic, but it doesn't tell you anything about ownership.

The most important change to functionality is that it has **implicit** conversions from raw
pointers, `std::shared_ptr<T>` and `std::unique_ptr<T>`. This facilitates the use of
`jss::object_ptr<T>` as a drop-in replacement for `T*` in function parameters. There is nothing you
can do with a `jss::object_ptr<T>` that you can't do with a `T*`, and in fact there is considerably
less that you can do. The same applies with `std::shared_ptr<T>` and `std::unique_ptr<T>`: you are
reducing functionality, so this is safe, and reducing typing for safe operations is a good thing.

The other change is the removal of the `release()` member function. An `object_ptr` doesn't own
anything, so it can't release ownership. To clear it, call `reset()`; if you want the wrapped
pointer, call `get()` first.

## Examples

~~~cplusplus
#include "object_ptr.hpp"
#include <iostream>
void foo(jss::object_ptr<int> p) {
if(p) {
std::cout << *p;
} else {
std::cout << "(null)";
}
std::cout << "\n";
}
int main() {
foo(nullptr);
int x= 42;
foo(&x);
auto sp= std::make_shared<int>(123);
foo(sp);
auto up= std::make_unique<int>(456);
foo(up);
}
~~~

The most common expected use case is as a function parameter, as in the example above. It is similar
to `std::string_view` from C++17 and `std::span` from C++20, in that it provides a view on data
managed elsewhere, and we only care about accessing that data, not how it is managed. It is
therefore ideally suited to places where you know the lifetime of the pointee exceeds the lifetime
of the `object_ptr`. Function arguments typically provide this guarantee, but it may also be used as
a class member where the pointee outlives the new class object, such as where the wrapper class
object is created and destroyed within a scope, and the pointee outlives that scope.

## License

This code is released under the [Boost Software License](https://www.boost.org/LICENSE_1_0.txt):

> Boost Software License - Version 1.0 - August 17th, 2003
>
> Permission is hereby granted, free of charge, to any person or organization
> obtaining a copy of the software and accompanying documentation covered by
> this license (the "Software") to use, reproduce, display, distribute,
> execute, and transmit the Software, and to prepare derivative works of the
> Software, and to permit third-parties to whom the Software is furnished to
> do so, all subject to the following:
>
> The copyright notices in the Software and this entire statement, including
> the above license grant, this restriction and the following disclaimer,
> must be included in all copies of the Software, in whole or in part, and
> all derivative works of the Software, unless such copies or derivative
> works are solely in the form of machine-executable object code generated by
> a source language processor.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
> SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
> FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
> ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> DEALINGS IN THE SOFTWARE.
224 changes: 224 additions & 0 deletions lib/object_ptr/object_ptr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#ifndef JSS_OBJECT_PTR_HPP
#define JSS_OBJECT_PTR_HPP
#include <cstddef>
#include <utility>
#include <functional>
#include <memory>
#include <type_traits>

namespace jss {
namespace detail {
/// Detect the presence of operator*, operator-> and .get() for the
/// given type
template <typename Ptr, bool= std::is_class<Ptr>::value>
struct has_smart_pointer_ops {
using false_test= char;
template <typename T> struct true_test { false_test dummy[2]; };

template <typename T> static false_test test_op_star(...);
template <typename T>
static true_test<decltype(*std::declval<T const &>())>
test_op_star(T *);

template <typename T> static false_test test_op_arrow(...);
template <typename T>
static true_test<decltype(std::declval<T const &>().operator->())>
test_op_arrow(T *);

template <typename T> static false_test test_get(...);
template <typename T>
static true_test<decltype(std::declval<T const &>().get())>
test_get(T *);

static constexpr bool value=
!std::is_same<decltype(test_get<Ptr>(0)), false_test>::value &&
!std::is_same<
decltype(test_op_arrow<Ptr>(0)), false_test>::value &&
!std::is_same<
decltype(test_op_star<Ptr>(0)), false_test>::value;
};

/// Non-class types can't be smart pointers
template <typename Ptr>
struct has_smart_pointer_ops<Ptr, false> : std::false_type {};

/// Ensure that the smart pointer operations give consistent return
/// types
template <typename Ptr>
struct smart_pointer_ops_consistent
: std::integral_constant<
bool,
std::is_pointer<decltype(
std::declval<Ptr const &>().get())>::value &&
std::is_reference<decltype(
*std::declval<Ptr const &>())>::value &&
std::is_pointer<decltype(
std::declval<Ptr const &>().operator->())>::value &&
std::is_same<
decltype(std::declval<Ptr const &>().get()),
decltype(std::declval<Ptr const &>().
operator->())>::value &&
std::is_same<
decltype(*std::declval<Ptr const &>().get()),
decltype(*std::declval<Ptr const &>())>::value> {};

/// Assume Ptr is a smart pointer if it has the relevant ops and they
/// are consistent
template <typename Ptr, bool= has_smart_pointer_ops<Ptr>::value>
struct is_smart_pointer
: std::integral_constant<
bool, smart_pointer_ops_consistent<Ptr>::value> {};

/// If Ptr doesn't have the relevant ops then it can't be a smart
/// pointer
template <typename Ptr>
struct is_smart_pointer<Ptr, false> : std::false_type {};

/// Check if Ptr is a smart pointer that holds a pointer convertible to
/// T*
template <typename Ptr, typename T, bool= is_smart_pointer<Ptr>::value>
struct is_convertible_smart_pointer
: std::integral_constant<
bool, std::is_convertible<
decltype(std::declval<Ptr const &>().get()),
T *>::value> {};

/// If Ptr isn't a smart pointer then we don't want it
template <typename Ptr, typename T>
struct is_convertible_smart_pointer<Ptr, T, false> : std::false_type {};

}

/// A basic "smart" pointer that points to an individual object it does not
/// own. Unlike a raw pointer, it does not support pointer arithmetic or
/// array operations, and the pointee cannot be accidentally deleted. It
/// supports implicit conversion from any smart pointer that holds a pointer
/// convertible to T*
template <typename T> class object_ptr {
public:
/// Construct a null pointer
constexpr object_ptr() noexcept : ptr(nullptr) {}
/// Construct a null pointer
constexpr object_ptr(std::nullptr_t) noexcept : ptr(nullptr) {}
/// Construct an object_ptr from a raw pointer
constexpr object_ptr(T *ptr_) noexcept : ptr(ptr_) {}
/// Construct an object_ptr from a raw pointer convertible to T*, such
/// as BaseOfT*
template <
typename U,
typename= std::enable_if_t<std::is_convertible<U *, T *>::value>>
constexpr object_ptr(U *ptr_) noexcept : ptr(ptr_) {}
/// Construct an object_ptr from a smart pointer that holds a pointer
/// convertible to T*,
/// such as shared_ptr<T> or unique_ptr<BaseOfT>
template <
typename Ptr,
typename= std::enable_if_t<
detail::is_convertible_smart_pointer<Ptr, T>::value>>
constexpr object_ptr(Ptr const &other) noexcept : ptr(other.get()) {}

/// Get the raw pointer value
constexpr T *get() const noexcept {
return ptr;
}

/// Dereference the pointer
constexpr T &operator*() const noexcept {
return *ptr;
}

/// Dereference the pointer for ptr->m usage
constexpr T *operator->() const noexcept {
return ptr;
}

/// Allow if(ptr) to test for null
constexpr explicit operator bool() const noexcept {
return ptr != nullptr;
}

/// Convert to a raw pointer where necessary
constexpr explicit operator T *() const noexcept {
return ptr;
}

/// !ptr is true iff ptr is null
constexpr bool operator!() const noexcept {
return !ptr;
}

/// Change the value
void reset(T *ptr_= nullptr) noexcept {
ptr= ptr_;
}

/// Check for equality
friend constexpr bool
operator==(object_ptr const &lhs, object_ptr const &rhs) noexcept {
return lhs.ptr == rhs.ptr;
}

/// Check for inequality
friend constexpr bool
operator!=(object_ptr const &lhs, object_ptr const &rhs) noexcept {
return !(lhs == rhs);
}

/// a<b provides a total order
friend constexpr bool
operator<(object_ptr const &lhs, object_ptr const &rhs) noexcept {
return std::less<void>()(lhs.ptr, rhs.ptr);
}
/// a>b is b<a
friend constexpr bool
operator>(object_ptr const &lhs, object_ptr const &rhs) noexcept {
return rhs < lhs;
}
/// a<=b is !(b<a)
friend constexpr bool
operator<=(object_ptr const &lhs, object_ptr const &rhs) noexcept {
return !(rhs < lhs);
}
/// a<=b is b<=a
friend constexpr bool
operator>=(object_ptr const &lhs, object_ptr const &rhs) noexcept {
return rhs <= lhs;
}

protected:
/// The stored pointer
T *ptr;
};

}

namespace std {
/// Allow hashing object_ptrs so they can be used as keys in unordered_map
template <typename T> struct hash<jss::object_ptr<T>> {
constexpr size_t operator()(jss::object_ptr<T> const &p) const
noexcept {
return hash<T *>()(p.get());
}
};

/// Do a static_cast with object_ptr
template <typename To, typename From>
typename std::enable_if<
sizeof(decltype(static_cast<To *>(std::declval<From *>()))) != 0,
jss::object_ptr<To>>::type
static_pointer_cast(jss::object_ptr<From> p) {
return static_cast<To *>(p.get());
}

/// Do a dynamic_cast with object_ptr
template <typename To, typename From>
typename std::enable_if<
sizeof(decltype(dynamic_cast<To *>(std::declval<From *>()))) != 0,
jss::object_ptr<To>>::type
dynamic_pointer_cast(jss::object_ptr<From> p) {
return dynamic_cast<To *>(p.get());
}

}

#endif
5 changes: 4 additions & 1 deletion src/CMakeSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ src/common/sphere_library/CSObjList.h
src/common/sphere_library/CSObjListRec.h
src/common/sphere_library/CSObjSortArray.h
src/common/sphere_library/CSPtrTypeArray.h
src/common/sphere_library/CSSortedVector.h
src/common/sphere_library/CSTypedArray.h
src/common/sphere_library/CSQueue.cpp
src/common/sphere_library/CSQueue.h
Expand All @@ -262,6 +261,8 @@ src/common/sphere_library/smutex.cpp
src/common/sphere_library/squeues.h
src/common/sphere_library/sresetevents.cpp
src/common/sphere_library/sresetevents.h
src/common/sphere_library/ssorted_vector.h
src/common/sphere_library/sptr.h
src/common/sphere_library/sptr_containers.h
src/common/sphere_library/sstacks.h
src/common/sphere_library/sstring.cpp
Expand Down Expand Up @@ -436,6 +437,8 @@ src/game/clients/CClientTarg.cpp
src/game/clients/CClientTooltip.h
src/game/clients/CClientTooltip.cpp
src/game/clients/CClientUse.cpp
src/game/clients/CGlobalChatChanMember.cpp
src/game/clients/CGlobalChatChanMember.h
src/game/clients/CGMPage.cpp
src/game/clients/CGMPage.h
src/game/clients/CParty.cpp
Expand Down
Loading

0 comments on commit ab1404c

Please sign in to comment.