You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdegames/libkdegames/kgame/kgameerror.cpp

81 lines
2.1 KiB

/*
This file is part of the KDE games library
Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
Copyright (C) 2001 Martin Heni (martin@heni-online.de)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/*
$Id$
*/
#include "kgameerror.h"
#include "kgamemessage.h"
#include <klocale.h>
TQByteArray KGameError::errVersion(int remoteVersion)
{
TQByteArray b;
TQDataStream s(b, IO_WriteOnly);
s << (TQ_INT32)KGameMessage::version();
s << (TQ_INT32)remoteVersion;
return b;
}
TQByteArray KGameError::errCookie(int localCookie, int remoteCookie)
{
TQByteArray b;
TQDataStream s(b, IO_WriteOnly);
s << (TQ_INT32)localCookie;
s << (TQ_INT32)remoteCookie;
return b;
}
TQString KGameError::errorText(int errorCode, const TQByteArray& message)
{
TQDataStream s(message, IO_ReadOnly);
return errorText(errorCode, s);
}
TQString KGameError::errorText(int errorCode, TQDataStream& s)
{
TQString text;
switch (errorCode) {
case Cookie:
{
TQ_INT32 cookie1;
TQ_INT32 cookie2;
s >> cookie1;
s >> cookie2;
text = i18n("Cookie mismatch!\nExpected Cookie: %1\nReceived Cookie: %2").tqarg(cookie1).tqarg(cookie2);
break;
}
case Version:
{
TQ_INT32 version1;
TQ_INT32 version2;
s >> version1;
s >> version2;
text = i18n("KGame Version mismatch!\nExpected Version: %1\nReceived Version: %2\n").tqarg(version1).tqarg(version2);
break;
}
default:
text = i18n("Unknown error code %1").tqarg(errorCode);
}
return text;
}