kgameerror.cpp
00001 /* 00002 This file is part of the TDE games library 00003 Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) 00004 Copyright (C) 2001 Martin Heni (martin@heni-online.de) 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 /* 00021 $Id$ 00022 */ 00023 00024 #include "kgameerror.h" 00025 #include "kgamemessage.h" 00026 00027 #include <tdelocale.h> 00028 00029 TQByteArray KGameError::errVersion(int remoteVersion) 00030 { 00031 TQByteArray b; 00032 TQDataStream s(b, IO_WriteOnly); 00033 s << (TQ_INT32)KGameMessage::version(); 00034 s << (TQ_INT32)remoteVersion; 00035 return b; 00036 } 00037 00038 TQByteArray KGameError::errCookie(int localCookie, int remoteCookie) 00039 { 00040 TQByteArray b; 00041 TQDataStream s(b, IO_WriteOnly); 00042 s << (TQ_INT32)localCookie; 00043 s << (TQ_INT32)remoteCookie; 00044 return b; 00045 } 00046 00047 TQString KGameError::errorText(int errorCode, const TQByteArray& message) 00048 { 00049 TQDataStream s(message, IO_ReadOnly); 00050 return errorText(errorCode, s); 00051 } 00052 00053 TQString KGameError::errorText(int errorCode, TQDataStream& s) 00054 { 00055 TQString text; 00056 switch (errorCode) { 00057 case Cookie: 00058 { 00059 TQ_INT32 cookie1; 00060 TQ_INT32 cookie2; 00061 s >> cookie1; 00062 s >> cookie2; 00063 text = i18n("Cookie mismatch!\nExpected Cookie: %1\nReceived Cookie: %2").arg(cookie1).arg(cookie2); 00064 break; 00065 } 00066 case Version: 00067 { 00068 TQ_INT32 version1; 00069 TQ_INT32 version2; 00070 s >> version1; 00071 s >> version2; 00072 text = i18n("KGame Version mismatch!\nExpected Version: %1\nReceived Version: %2\n").arg(version1).arg(version2); 00073 break; 00074 } 00075 default: 00076 text = i18n("Unknown error code %1").arg(errorCode); 00077 } 00078 return text; 00079 } 00080