mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-26 17:52:54 +00:00
You shall fix ze bugs you shall ve happy
This commit is contained in:
parent
0803f67f47
commit
3ece2a588d
|
|
@ -58,7 +58,7 @@ void BufferedOutputStream::write(byteArray b, unsigned int offset, unsigned int
|
|||
{
|
||||
for(unsigned int i = 0; i < length; i++ )
|
||||
{
|
||||
write( b[offset+i] );
|
||||
write( static_cast<unsigned int>(b[offset+i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -84,4 +84,4 @@ void BufferedOutputStream::write(unsigned int b)
|
|||
{
|
||||
flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ int ByteArrayInputStream::read()
|
|||
if( pos >= count )
|
||||
return -1;
|
||||
else
|
||||
return buf[pos++];
|
||||
return static_cast<unsigned int>(buf[pos++]);
|
||||
}
|
||||
|
||||
//Reads some number of bytes from the input stream and stores them into the buffer array b.
|
||||
|
|
@ -115,4 +115,4 @@ __int64 ByteArrayInputStream::skip(__int64 n)
|
|||
ByteArrayInputStream::~ByteArrayInputStream()
|
||||
{
|
||||
if(buf.data != NULL) delete [] buf.data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ bool DataInputStream::readFully(byteArray b)
|
|||
}
|
||||
else
|
||||
{
|
||||
b[i] = byteRead;
|
||||
b[i] = static_cast<std::byte>(byteRead);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -543,4 +543,4 @@ __int64 DataInputStream::skip(__int64 n)
|
|||
int DataInputStream::skipBytes(int n)
|
||||
{
|
||||
return skip(n);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ void DataOutputStream::close()
|
|||
//v - a byte value to be written.
|
||||
void DataOutputStream::writeByte(byte a)
|
||||
{
|
||||
stream->write( a );
|
||||
stream->write( static_cast<unsigned int>(a) );
|
||||
}
|
||||
|
||||
//Converts the double argument to a long using the doubleToLongBits method in class Double,
|
||||
|
|
@ -176,7 +176,7 @@ void DataOutputStream::writeChars(const wstring& str)
|
|||
//v - a boolean value to be written.
|
||||
void DataOutputStream::writeBoolean(bool b)
|
||||
{
|
||||
stream->write( b ? (byte)1 : (byte)0 );
|
||||
stream->write( b ? 1 : 0 );
|
||||
// TODO 4J Stu - Error handling?
|
||||
written += 1;
|
||||
}
|
||||
|
|
@ -265,4 +265,4 @@ void DataOutputStream::writePlayerUID(PlayerUID player)
|
|||
#else
|
||||
writeLong(player);
|
||||
#endif // PS3
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
#include "File.h"
|
||||
#include "FileInputStream.h"
|
||||
#include "../Minecraft.Client/Windows64/Windows64_App.h"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h> // for close()
|
||||
|
||||
extern CConsoleMinecraftApp app;
|
||||
|
||||
//Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.
|
||||
//A new FileDescriptor object is created to represent this file connection.
|
||||
|
|
@ -29,6 +34,8 @@ FileInputStream::FileInputStream(const File &file)
|
|||
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
|
||||
NULL // Unsupported
|
||||
);
|
||||
#elif defined(__linux__)
|
||||
m_fileHandle = open(pchFilename, O_RDONLY);
|
||||
#else
|
||||
m_fileHandle = CreateFile(
|
||||
pchFilename, // file name
|
||||
|
|
@ -52,15 +59,33 @@ FileInputStream::FileInputStream(const File &file)
|
|||
FileInputStream::~FileInputStream()
|
||||
{
|
||||
if( m_fileHandle != INVALID_HANDLE_VALUE )
|
||||
#ifndef __linux__
|
||||
CloseHandle( m_fileHandle );
|
||||
#else
|
||||
::close( m_fileHandle );
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
ssize_t ReadFile(int fd, void* buffer, size_t byteRead, DWORD* numberOfBytesRead, int JustAddANULL) {
|
||||
ssize_t result = read(fd, buffer, byteRead);
|
||||
|
||||
if (result == -1) {
|
||||
perror("read failed");
|
||||
return -1;
|
||||
} else {
|
||||
*numberOfBytesRead = result;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif // __linux__
|
||||
|
||||
//Reads a byte of data from this input stream. This method blocks if no input is yet available.
|
||||
//Returns:
|
||||
//the next byte of data, or -1 if the end of the file is reached.
|
||||
int FileInputStream::read()
|
||||
{
|
||||
byte byteRead = 0;
|
||||
byte byteRead = static_cast<std::byte>(0);
|
||||
DWORD numberOfBytesRead;
|
||||
|
||||
BOOL bSuccess = ReadFile(
|
||||
|
|
@ -69,7 +94,7 @@ int FileInputStream::read()
|
|||
1, // number of bytes to read
|
||||
&numberOfBytesRead, // number of bytes read
|
||||
NULL // overlapped buffer
|
||||
);
|
||||
);
|
||||
|
||||
if( bSuccess==FALSE )
|
||||
{
|
||||
|
|
@ -83,7 +108,7 @@ int FileInputStream::read()
|
|||
return -1;
|
||||
}
|
||||
|
||||
return byteRead;
|
||||
return static_cast<int>(byteRead);
|
||||
}
|
||||
|
||||
//Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.
|
||||
|
|
@ -166,7 +191,7 @@ void FileInputStream::close()
|
|||
return;
|
||||
}
|
||||
|
||||
BOOL result = CloseHandle( m_fileHandle );
|
||||
BOOL result = ::close( m_fileHandle );
|
||||
|
||||
if( result == 0 )
|
||||
{
|
||||
|
|
@ -201,4 +226,4 @@ __int64 FileInputStream::skip(__int64 n)
|
|||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "stdafx.h"
|
||||
#include "Random.h"
|
||||
#include <ctime>
|
||||
#include <cstdint> // for int64_t
|
||||
#include "System.h"
|
||||
|
||||
Random::Random()
|
||||
|
|
@ -7,8 +9,13 @@ Random::Random()
|
|||
// 4J - jave now uses the system nanosecond counter added to a "seedUniquifier" to get an initial seed. Our nanosecond timer is actually only millisecond accuate, so
|
||||
// use QueryPerformanceCounter here instead
|
||||
__int64 seed;
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&seed);
|
||||
seed += 8682522807148012LL;
|
||||
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
seed = ts.tv_sec * 1000000000LL + ts.tv_nsec;
|
||||
|
||||
seed += 8682522807148012LL;
|
||||
|
||||
setSeed(seed);
|
||||
}
|
||||
|
|
@ -103,4 +110,4 @@ __int64 Random::nextLong()
|
|||
bool Random::nextBoolean()
|
||||
{
|
||||
return next(1) != 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@
|
|||
#include "SocketAddress.h"
|
||||
#include "Socket.h"
|
||||
#include "ThreadName.h"
|
||||
#include "..\Minecraft.Client\ServerConnection.h"
|
||||
#include "../Minecraft.Client/ServerConnection.h"
|
||||
#include <algorithm>
|
||||
#include "..\Minecraft.Client\PS3\PS3Extras\ShutdownManager.h"
|
||||
#include "../Minecraft.Client/PS3/PS3Extras/ShutdownManager.h"
|
||||
#include "../Minecraft.Client/Windows64/Windows64_App.h"
|
||||
|
||||
extern CConsoleMinecraftApp app;
|
||||
|
||||
// This current socket implementation is for the creation of a single local link. 2 sockets can be created, one for either end of this local
|
||||
// link, the end (0 or 1) is passed as a parameter to the ctor.
|
||||
|
|
@ -22,6 +25,7 @@ void Socket::Initialise(ServerConnection *serverConnection)
|
|||
|
||||
// Only initialise everything else once - just setting up static data, one time xrnm things, thread for ticking sockets
|
||||
static bool init = false;
|
||||
#if !defined(__linux__)
|
||||
if( init )
|
||||
{
|
||||
for( int i = 0; i < 2; i++ )
|
||||
|
|
@ -38,11 +42,14 @@ void Socket::Initialise(ServerConnection *serverConnection)
|
|||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
init = true;
|
||||
|
||||
for( int i = 0; i < 2; i++ )
|
||||
{
|
||||
#if !defined(__linux__)
|
||||
InitializeCriticalSection(&Socket::s_hostQueueLock[i]);
|
||||
#endif
|
||||
s_hostOutStream[i] = new SocketOutputStreamLocal(i);
|
||||
s_hostInStream[i] = new SocketInputStreamLocal(i);
|
||||
}
|
||||
|
|
@ -79,7 +86,9 @@ Socket::Socket(INetworkPlayer *player, bool response /* = false*/, bool hostLoca
|
|||
|
||||
for( int i = 0; i < 2; i++ )
|
||||
{
|
||||
#if !defined(__linux__)
|
||||
InitializeCriticalSection(&m_queueLockNetwork[i]);
|
||||
#endif // __linux__
|
||||
m_inputStream[i] = NULL;
|
||||
m_outputStream[i] = NULL;
|
||||
m_endClosed[i] = false;
|
||||
|
|
@ -127,6 +136,7 @@ void Socket::setPlayer(INetworkPlayer *player)
|
|||
|
||||
void Socket::pushDataToQueue(const BYTE * pbData, DWORD dwDataSize, bool fromHost /*= true*/)
|
||||
{
|
||||
#ifndef __linux__
|
||||
int queueIdx = SOCKET_CLIENT_END;
|
||||
if(!fromHost)
|
||||
queueIdx = SOCKET_SERVER_END;
|
||||
|
|
@ -143,6 +153,7 @@ void Socket::pushDataToQueue(const BYTE * pbData, DWORD dwDataSize, bool fromHos
|
|||
m_queueNetwork[queueIdx].push(*pbData++);
|
||||
}
|
||||
LeaveCriticalSection(&m_queueLockNetwork[queueIdx]);
|
||||
#endif // __linux__
|
||||
}
|
||||
|
||||
void Socket::addIncomingSocket(Socket *socket)
|
||||
|
|
@ -259,6 +270,7 @@ Socket::SocketInputStreamLocal::SocketInputStreamLocal(int queueIdx)
|
|||
// Try and get an input byte, blocking until one is available
|
||||
int Socket::SocketInputStreamLocal::read()
|
||||
{
|
||||
#if !defined(__linux__)
|
||||
while(m_streamOpen && ShutdownManager::ShouldRun(ShutdownManager::eConnectionReadThreads))
|
||||
{
|
||||
if(TryEnterCriticalSection(&s_hostQueueLock[m_queueIdx]))
|
||||
|
|
@ -274,6 +286,7 @@ int Socket::SocketInputStreamLocal::read()
|
|||
}
|
||||
Sleep(1);
|
||||
}
|
||||
#endif // __linux__
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -286,6 +299,7 @@ int Socket::SocketInputStreamLocal::read(byteArray b)
|
|||
// Try and get an input range of bytes, blocking until enough bytes are available
|
||||
int Socket::SocketInputStreamLocal::read(byteArray b, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#ifndef __linux__
|
||||
while(m_streamOpen)
|
||||
{
|
||||
if(TryEnterCriticalSection(&s_hostQueueLock[m_queueIdx]))
|
||||
|
|
@ -304,15 +318,18 @@ int Socket::SocketInputStreamLocal::read(byteArray b, unsigned int offset, unsig
|
|||
}
|
||||
Sleep(1);
|
||||
}
|
||||
#endif // __linux__
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Socket::SocketInputStreamLocal::close()
|
||||
{
|
||||
#ifndef __linux__
|
||||
m_streamOpen = false;
|
||||
EnterCriticalSection(&s_hostQueueLock[m_queueIdx]);
|
||||
s_hostQueue[m_queueIdx].empty();
|
||||
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
|
||||
#endif // __linux__
|
||||
}
|
||||
|
||||
/////////////////////////////////// Socket for output, on local connection ////////////////////
|
||||
|
|
@ -325,6 +342,7 @@ Socket::SocketOutputStreamLocal::SocketOutputStreamLocal(int queueIdx)
|
|||
|
||||
void Socket::SocketOutputStreamLocal::write(unsigned int b)
|
||||
{
|
||||
#ifndef __linux__
|
||||
if( m_streamOpen != true )
|
||||
{
|
||||
return;
|
||||
|
|
@ -332,6 +350,7 @@ void Socket::SocketOutputStreamLocal::write(unsigned int b)
|
|||
EnterCriticalSection(&s_hostQueueLock[m_queueIdx]);
|
||||
s_hostQueue[m_queueIdx].push((byte)b);
|
||||
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
|
||||
#endif // __linux__
|
||||
}
|
||||
|
||||
void Socket::SocketOutputStreamLocal::write(byteArray b)
|
||||
|
|
@ -341,6 +360,7 @@ void Socket::SocketOutputStreamLocal::write(byteArray b)
|
|||
|
||||
void Socket::SocketOutputStreamLocal::write(byteArray b, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#ifndef __linux__
|
||||
if( m_streamOpen != true )
|
||||
{
|
||||
return;
|
||||
|
|
@ -353,14 +373,17 @@ void Socket::SocketOutputStreamLocal::write(byteArray b, unsigned int offset, un
|
|||
}
|
||||
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
|
||||
MemSect(0);
|
||||
#endif // __linux__
|
||||
}
|
||||
|
||||
void Socket::SocketOutputStreamLocal::close()
|
||||
{
|
||||
#ifndef __linux__
|
||||
m_streamOpen = false;
|
||||
EnterCriticalSection(&s_hostQueueLock[m_queueIdx]);
|
||||
s_hostQueue[m_queueIdx].empty();
|
||||
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
|
||||
#endif // __linux__
|
||||
}
|
||||
|
||||
/////////////////////////////////// Socket for input, on network connection ////////////////////
|
||||
|
|
@ -375,6 +398,7 @@ Socket::SocketInputStreamNetwork::SocketInputStreamNetwork(Socket *socket, int q
|
|||
// Try and get an input byte, blocking until one is available
|
||||
int Socket::SocketInputStreamNetwork::read()
|
||||
{
|
||||
#ifndef __linux__
|
||||
while(m_streamOpen && ShutdownManager::ShouldRun(ShutdownManager::eConnectionReadThreads))
|
||||
{
|
||||
if(TryEnterCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]))
|
||||
|
|
@ -390,6 +414,7 @@ int Socket::SocketInputStreamNetwork::read()
|
|||
}
|
||||
Sleep(1);
|
||||
}
|
||||
#endif // __linux__
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -402,6 +427,7 @@ int Socket::SocketInputStreamNetwork::read(byteArray b)
|
|||
// Try and get an input range of bytes, blocking until enough bytes are available
|
||||
int Socket::SocketInputStreamNetwork::read(byteArray b, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#ifndef __linux__
|
||||
while(m_streamOpen)
|
||||
{
|
||||
if(TryEnterCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]))
|
||||
|
|
@ -420,6 +446,7 @@ int Socket::SocketInputStreamNetwork::read(byteArray b, unsigned int offset, uns
|
|||
}
|
||||
Sleep(1);
|
||||
}
|
||||
#endif // __linux__
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -531,4 +558,4 @@ void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, unsigned int
|
|||
void Socket::SocketOutputStreamNetwork::close()
|
||||
{
|
||||
m_streamOpen = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
#include <sys/sys_time.h>
|
||||
#endif
|
||||
#include "System.h"
|
||||
#if defined(__linux__)
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <ctime>
|
||||
#endif // __linux__
|
||||
|
||||
template <class T> void System::arraycopy(arrayWithLength<T> src, unsigned int srcPos, arrayWithLength<T> *dst, unsigned int dstPos, unsigned int length)
|
||||
{
|
||||
|
|
@ -16,7 +21,7 @@ template <class T> void System::arraycopy(arrayWithLength<T> src, unsigned int s
|
|||
ArrayCopyFunctionDefinition(Node *)
|
||||
ArrayCopyFunctionDefinition(Biome *)
|
||||
|
||||
void System::arraycopy(arrayWithLength<BYTE> src, unsigned int srcPos, arrayWithLength<BYTE> *dst, unsigned int dstPos, unsigned int length)
|
||||
void System::arraycopy(arrayWithLength<byte> src, unsigned int srcPos, arrayWithLength<byte> *dst, unsigned int dstPos, unsigned int length)
|
||||
{
|
||||
assert( srcPos >=0 && srcPos <= src.length);
|
||||
assert( srcPos + length <= src.length );
|
||||
|
|
@ -52,7 +57,13 @@ void System::arraycopy(arrayWithLength<int> src, unsigned int srcPos, arrayWithL
|
|||
//The current value of the system timer, in nanoseconds.
|
||||
__int64 System::nanoTime()
|
||||
{
|
||||
#if !defined(__linux__)
|
||||
return GetTickCount() * 1000000LL;
|
||||
#else
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return static_cast<int64_t>(ts.tv_sec) * 1000000000LL + ts.tv_nsec;
|
||||
#endif // __linux__
|
||||
}
|
||||
|
||||
//Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond,
|
||||
|
|
@ -87,7 +98,13 @@ __int64 System::currentTimeMillis()
|
|||
sceRtcGetCurrentClockLocalTime(&Time);
|
||||
__int64 systTime = (((((((Time.day * 24) + Time.hour) * 60) + Time.minute) * 60) + Time.second) * 1000) + (Time.microsecond / 1000);
|
||||
return systTime;*/
|
||||
#elif defined(__linux__)
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
long long unix_time = tv.tv_sec;
|
||||
long long file_time = (unix_time + 11644473600LL) * 10000000LL + tv.tv_usec * 10;
|
||||
|
||||
return file_time;
|
||||
#else
|
||||
|
||||
SYSTEMTIME UTCSysTime;
|
||||
|
|
|
|||
Loading…
Reference in a new issue